Reputation: 685
I am having 3 tables:
Now how can I build relation in all scenarios, for example I want to view the upload_file of an user.
I am new to rails. Please help. Thanks in advance.
Upvotes: 1
Views: 33
Reputation: 2382
Well, try to think of what you want with your app in english first, and ORM later. Lets say
You want User
to have multiple Timesheet
and each TimeSheet
to have one Attachment
. So you can say
class User < AR::Base
has_many :timesheets
end
class TimeSheet < AR::Base
has_one :attachment
end
and your database fields need some extra parameters, timesheets
need user_id
and attachments
need timesheet_id
.
Hence I think, that you should also learn a bit about databases while learning rails, and RTFM
Upvotes: 2