On Mar 2, 2012, at 5:29 AM, edap e. wrote: > Hello, i'm developing a Rails3 application mixing together Gmap4rails > and Devise to build a CMS that allows web developers to make maps > application quickly. The CMS now is based on 2 models. > Location, stores latitude, longitude and name of the marker > Categories, stores the name of the category and the location_id > They are related through a HABTM relationship, > http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association > > My question is, how should I add information related to a Location, that > are dipendent on the category? > For example, a Location under the Category "Bar" needs this fields: > "opening_time", "closing_time", "medium_drink_prize" ecc.. > A Location under the Category "Hotel" needs this information: > "medium_room_prize", "stars" ecc.. > Sometimes the location has 2 categories (has the relationships type self > explained), for examole "Bar", and "Disco", that need both the > Categories field > to be completed. > > I think that I should add for every Category a Detail table, that stores > for each field the field's type (file, text, textarea ecc..), and the > name. Category has one Detail, and Detail belongs to Category, but I'm > not sure about. > > What would you suggest? > thanks in advance
Have you read the Rails Guide about ActiveRecord Associations? Particularly the part about Has Many Through? That sounds exactly like what you need. The idea there is that instead of the "dumb" HABTM join, with just a join table of two integer columns, you use a full model to describe the relationship. That way your join objects can be decorated with additional data that relate specifically to the connection between the two models they relate. Walter -- 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.

