Hi,
I am new to RoR and have been pulling my hair out trying to figure out
associations.
Lets say I have 2 tables: vehicles and vehicle_types. ONE vehicle HAS
ONE vehicle_type. Therefore, in my opinion, vehicle_type belongs_to
vehicle.
Hence, vehicle_types will contain the vehicle foreign key. To me this is
already weird. I would like vehicle_types to be a table containing a
column that lists types of vehicles- "truck", "car", "bus", etc. It does
not need to know what vehicle is associated with it. The vehicles table
needs to know what vehicle_type it is.
I would like to use the vehicle_types table to populate a Select Menu on
a form. If I create the associations as suggested by RoR, with the
foreign key going on the belongs_to table (vehicle_types), the Select
Menu would be populated with duplicate vehicle_types. EG:
vehicle_id vehicle_type_id type
1 1 car
2 2 truck
3 3 car
Does this make sense?
Like I said I have spent days reading over the associations again and
again but I just can't figure it out. Any help would be greatly
appreciated.
Thanks.
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment