I'm having following tables, Issues, Users, Reasons and Images. Basically Issues have many Reasons
and my goal is to display the attachment image of the 'Reasons' as well as the author of the post (Users).
1. Users table associated with Reasons
2. Both Users and Reasons are associated with Images table (foreign key 'image_id').
It works in find query when associating
'Reasons.Images' or 'Reasons.Users.Images'
But not both! This is my code, which returns only for 'Reasons.Images'.
$this->Issues->findById($id)->contain([
'Reasons.Images',
'Reasons.Users.Images'
]);
So how I get the Image association of both the tables or Should my approach be different?
reason_id
when this should be aIssue hasMany Reason
association? Also the order is the same as in your question, you've just added another containment (respectively containment configuration)? Besides that, the find in your question works fine for me as is, the result will contain the reasons with their associated image and user, where the users have their image included too. – ndm