Ruby on Rails Monday, July 11, 2016

Johnny Stewart wrote in post #1184570:
> No tutorial that I know of..
>
> You have the same information for all user types, namely just the
> important information for users. So - you keep password, username, first
> name, last name, email address etc in the User table.
>
> Stuff like sport, training ground, weight, height, body-fat etc would go
> in a table like AthleticInfo
>
> stuff like restaurant, food speciality, chef qualifications etc would go
> in a table like ChefInfo
>
> then if user1 is a chef, he would have all the user info + type Chef and
> he would have an entry in the chef table
>
> user2 if she was a footballer would have all the user info + type
> Athlete and she would have an entry in the athlete table
>
> So, you don't need to keep all the chef or athlete data in the user
> table - you just have a reference to that info in the relevant table..

Thanks for your response.
But isn't this a polymorphic association?. I'am trying to do exactly
that with a polymorphic association, that is, create the user table with
all the common information, and with meta_type:string (that saves the
type of user) and meta_id:integer (that saves the id of the user on his
type of user table), and implement the associations y the models after,
like this:
class User < ActiveRecord::Base
...
belongs_to :meta, :polymorphic => true
end

class Chef < ActiveRecord::Base
has_one :user, :as => :meta
...
end
(more models)

So , each register user will have an entry in the user table, and on his
user type table.
The problem is that i don't know to modify the Registration controller
of Devise to do that.
Regards!

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2e30b2f890b2f97ee096d1e6333eea6c%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment