HI all, newbie question, I have the following DB Structure actors - id - name - age movie - id - name - year role - id - name - requiresSwimming - requiresHorseskills movie_actor - actor_id - movie_id - role_id How should I map this in my model in rails? An actor can only have one role in each movie Thanks J --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It makes a little more sense to me to have the db look like this: actor - id - name - birth_date movie - id - name - year role - actor_id - movie_id - requires_swimming - requires_horsemanship Then your models would look like this class Actor < ActiveRecord::Base has_many :roles has_many :movies, :through => :roles end class Movie < ActiveRecord::Base has_many :roles has_many :actors, :through => :roles end class Role < ActiveRecord::Base belongs_to :actor belongs_to :movie end -- Building an e-commerce site with Rails? http://www.agilewebdevelopment.com/rails-ecommerce Meet up at RailsConf: http://railsconf2007.conferencemeetup.com/ On Feb 19, 2007, at 5:06 PM, macarthy wrote:> > HI all, newbie question, I have the following DB Structure > > actors > - id > - name > - age > > movie > - id > - name > - year > > role > - id > - name > - requiresSwimming > - requiresHorseskills > > movie_actor > - actor_id > - movie_id > - role_id > > How should I map this in my model in rails? An actor can only have > one role in each movie > > Thanks J >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Lol? Why did you post that qeustion again? i answered your first thread 1 hour ago? On 20 Feb., 15:17, Benjamin Curtis <r...-4dtGyw5agdmakBO8gow8eQ@public.gmane.org> wrote:> It makes a little more sense to me to have the db look like this: > > actor > - id > - name > - birth_date > > movie > - id > - name > - year > > role > - actor_id > - movie_id > - requires_swimming > - requires_horsemanship > > Then your models would look like this > > class Actor < ActiveRecord::Base > has_many :roles > has_many :movies, :through => :roles > end > > class Movie < ActiveRecord::Base > has_many :roles > has_many :actors, :through => :roles > end > > class Role < ActiveRecord::Base > belongs_to :actor > belongs_to :movie > end > > -- > Building an e-commerce site with Rails?http://www.agilewebdevelopment.com/rails-ecommerce > > Meet up at RailsConf:http://railsconf2007.conferencemeetup.com/ > > On Feb 19, 2007, at 5:06 PM, macarthy wrote: > > > > > > > HI all, newbie question, I have the following DB Structure > > > actors > > - id > > - name > > - age > > > movie > > - id > > - name > > - year > > > role > > - id > > - name > > - requiresSwimming > > - requiresHorseskills > > > movie_actor > > - actor_id > > - movie_id > > - role_id > > > How should I map this in my model in rails? An actor can only have > > one role in each movie > > > Thanks J- Zitierten Text ausblenden - > > - Zitierten Text anzeigen ---~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---