Forum: Ruby on Rails Relationships in RoR

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.
2ae59ce11de813dae1df728d80b748d5?d=identicon&s=25 Shanon (Guest)
on 2007-04-06 03:11
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
0c51049fb747cd60088e4878458e05d1?d=identicon&s=25 Rick Schumeyer (Guest)
on 2007-04-06 03:19
(Received via mailing list)
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.
D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2007-04-06 04:52
(Received via mailing list)
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.
This topic is locked and can not be replied to.