How to join multiple tables with one to one relationships in rails -
Ruby on Rail is very new to me. I'm trying to recover a set of columns from 3 different tables. I thought I could use the SQL View to retrieve my results, but there was no way to use the ideas in Rail. These are my tables 1) User table -> username, password and email 2) Usageetal table -> Foreign key: user_id, name, address 1, city etc. 3) Userwork version Description-> Foreign key: user_id, work address 1, work type etc.
These 3 tables have one relation, then Table 2 comes under Table 1 and Table 3 also comes from the table. Is related. Table 1 contains a user's description and a user function.
I want to get the user's email, name, address 1, city, work address 1, work type Join join
What is the best way to handle it?
is the data) Everything else in the model is just an optimization For example, address1 is defined as User.user_detail.address1
, for example.
If you have a user with
class user_detail: _ user_work_detail end class UserDetail is_to: user end class UserWorkDetail is_to: user end
< P> user_id
in the user_id
column and user_work_details
then everything is done for you if you need to customize later Can: Include models owned, but it is not necessary for everything.
Comments
Post a Comment