# Relationships in RoR

**URL:** <https://www.ruby-forum.com/t/relationships-in-ror/102741>\
**Category:** Rails\
**Created:** [April 6, 2007, 3:11am UTC](https://www.ruby-forum.com/t/relationships-in-ror/102741 "2007-04-06T03:11:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shanon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@Shanon](https://www.ruby-forum.com/u/Shanon)\
**Post date:** [April 6, 2007, 3:11am UTC](https://www.ruby-forum.com/t/relationships-in-ror/102741/1 "2007-04-06T03:11:10Z")

</div>

How does one setup relations between table

I have the has\_many and belongs\_to in the correct places (hopefully) but  
i think i have the migrations in the incorrect order

A user can create many jobs  
so i have

user has\_many jobs  
and jobs belongs\_to user

however i have the migration that creates the job table before i have  
the migration that creates the user table can i still get this to work  
and if not,  
How does one change the order of the migration with deleting the first  
one and creating it again

and does the migration need to have t.column user\_id, :int or will this  
be added automatically

---

<div class="post-metadata">

**Author:** ![Shanon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@Shanon](https://www.ruby-forum.com/u/Shanon)\
**Post date:** [April 6, 2007, 3:19am UTC](https://www.ruby-forum.com/t/relationships-in-ror/102741/2 "2007-04-06T03:19:11Z")

</div>

I believe you will need to re-order your migrations. I think you can  
just rename them, so if you have  
001\_create\_jobs.rb and 002\_create\_users.rb they need to become  
001\_create\_users.rb and 002\_create\_jobs.rb.

Yes, you need to specify the :user\_id column.

---

<div class="post-metadata">

**Author:** ![Shanon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@Shanon](https://www.ruby-forum.com/u/Shanon)\
**Post date:** [April 6, 2007, 4:52am UTC](https://www.ruby-forum.com/t/relationships-in-ror/102741/3 "2007-04-06T04:52:17Z")

</div>

That doesn’t matter. Migrations are for creating the tables in the  
database.  
Once you run the rake migrate command, both tables will be created, and  
it  
doesn’t matter what order they will be created in, you’ll end up with  
the  
same result.
