I know how to include nested resources in controller render like this:
render :json => @user, :include => {:profile}
My doubt is: is it possible to do this in models?
I tried many ways but it doesn't give me the user and his profile like this:
{
id: 1,
name: 'John',
profile: {
id: 64,
status: 'active'
}
}
I tried this in my model:
User.where(id: 1).includes(:profile)
And the output was:
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1
Profile Load (0.2ms) SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`user_id` IN (1)