having a hard time working out the logic of active record associations

I know it's supposed to be as straightforward as one to one, one to many and many to one, etc.
But RoR has belongs_to and has_one to cover one to one.
And it also has has_many, has_many :through, has_one :through and has_and_belongs_to_many.

So I'm creating a fictional website where I have users give me jobs through a website, users create themselves and a job at the same time. When I carry out my job, the User can then leave a Review linked only to that job.

Once users have created a Job, they can edit it or delete it.
When a job is done, Users can also delete their account if they want, but the Jobs must remain for me to see later, and the reviews must remain.

So my troubled mind is finding it hard to model the associations between the four tables: User, Address, Job, Review.
User has 1 Address, Address can have more than 1 User
Job has 1 User, User can have more than 1 Job
Job has one Review, Review has one Job.

Where do I make the foreign keys? one user or address or both?
It's just giving me a headache, and it shouldn't really, I've got a degree in engineering here.

Can anyone simplify or give me some advise?

Leave a Comment