0
Hi, I have a Model Comment
who is a belongs_to of User
, and a Model Profile
that also is a belongs_to of User
.
I can access User data easily through Comment.first.user
, for example, but I would like to access Profile
through the User
, without having to make several queries.
Both profiles and comments have a foreign key user_id
. How to make the results of both tables (comments and profiles) come out in the same query? Thanks in advance!
Update
I have the result of the User.find(1) query that would be
id:12 | email: [email protected] | password_digest:....
And I have the result of the query User.find(1). profile, which would be
name: João | lastname: Eduardo | user_id: 12
You can create a result in Activerecord with the union of these two tables?
email: [email protected] | name: João | lastname: Eduardo
The other question, is it possible to do this with . all, instead of . find or . Where ? I’ve done a lot of research on this, tried to use include, and joins and so far I haven’t been able to. I’m supposed to do two things, but I’m not sure.
Explain better by adding a code, it’s easier to understand
– Sveen