Forum: Ruby on Rails How do I represent this DB structure????

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
macarthy (Guest)
on 2007-02-20 03:07
(Received via mailing list)
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
Benjamin C. (Guest)
on 2007-02-20 16:18
(Received via mailing list)
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/
Thorsten (Guest)
on 2007-02-20 16:27
(Received via mailing list)
Lol? Why did you post that qeustion again? i answered your first
thread 1 hour ago?
This topic is locked and can not be replied to.