I have one User
model and StudentProfile
model associations are
class User < ApplicationRecord
has_one :student_profile
end
class StudentProfile < ApplicationRecord
belongs_to :user
end
我想呈现两个表的所有字段。该操作的SQL命令是
select * from users join student_profiles on student_profiles.user_id = users.id
但
User.joins(:student_profile)
shows only the fields of User
table.
有什么方法可以在活动记录查询中实现此sql?
select * from users join student_profiles on student_profiles.user_id = users.id