Ruby on Rails Wednesday, July 13, 2016

> 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!

No - its not polymorphic at all. The type column is there due to STI.

class User < ActiveRecord::Base
end

class Athlete < User
has_one :athlete_info, dependent: :destroy
end

class Chef < User
has_one :chef_info, dependent: :destroy
end

class AthleteInfo < ActiveRecord::Base
belongs_to :athlete
end

class ChefInfo < ActiveRecord::Base
belongs_to :chef
end

chef_info table is where the chef specific information is held, same for
athlete. No complication of polymorphism required..

J.

--
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/51378cfa03e3eb7420715168d43f23aa%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment