# How do I represent this DB structure?

**URL:** <https://www.ruby-forum.com/t/how-do-i-represent-this-db-structure/86123>\
**Category:** Rails\
**Created:** [February 20, 2007, 2:07am UTC](https://www.ruby-forum.com/t/how-do-i-represent-this-db-structure/86123 "2007-02-20T02:07:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![macarthy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@macarthy](https://www.ruby-forum.com/u/macarthy)\
**Post date:** [February 20, 2007, 2:07am UTC](https://www.ruby-forum.com/t/how-do-i-represent-this-db-structure/86123/1 "2007-02-20T02:07:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![macarthy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@macarthy](https://www.ruby-forum.com/u/macarthy)\
**Post date:** [February 20, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/how-do-i-represent-this-db-structure/86123/2 "2007-02-20T15:18:41Z")

</div>

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](http://www.agilewebdevelopment.com/rails-ecommerce)

Meet up at RailsConf:  
[http://railsconf2007.conferencemeetup.com/](http://railsconf2007.conferencemeetup.com/)

---

<div class="post-metadata">

**Author:** ![macarthy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@macarthy](https://www.ruby-forum.com/u/macarthy)\
**Post date:** [February 20, 2007, 3:27pm UTC](https://www.ruby-forum.com/t/how-do-i-represent-this-db-structure/86123/3 "2007-02-20T15:27:43Z")

</div>

Lol? Why did you post that qeustion again? i answered your first  
thread 1 hour ago?
