On Mar 2, 2012, at 11:53 AM, edap e. wrote: > Hey Walter, thanks for your reply. Yes I've read this part, but i've > thought that it was not the best solution, probably i was worng. > Today I've saw also this solution, that maybe fit my problem > http://www.unixgods.org/~tilo/Rails/Rails_polymprphic_has_many_through_relationships.html > > Please correct me if I'm wrong. You suggest me to do something like > this? > > class Location < ActiveRecord::Base > has_many :details > has_many :bars, :through => :details > has_many :discos, :through => :details > end > > class Detail < ActiveRecord::Base > belongs_to :Location > belongs_to :Bar > belongs_to :Disco > end > > class Bar < ActiveRecord::Base > has_many :details > has_many :Location, :through => :details > end > > class Disco < ActiveRecord::Base > has_many :details > has_many :Location, :through => :details > end > > thanks,
That sounds about right, but please check your naming very carefully. If you are using normal Rails conventions, then your relationships would look like this class Bar < ActiveRecord::Base has_many :details has_many :locations, :through => :details end etc. Always name the class Singular, Upper Case, CamelCased and always refer to the plural relationship the same as the table name -- plural, lower-case, and under_scored. Walter > > -- > 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 post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

