I have three models: User Image Group.
- User belongs to an image;
- Group belongs to a User (admin)
- Group Has and belongs to user;
- User has and belongs to group;
- User and group model are connected with
users_groupstable;
When I am viewing a group there is listing the members (Users, this works) I need to extract them images what should I do?
You should use the ContainableBehavior. It will allow you to control what data you pull.
First, add it to your AppModel. I also always set
$recursive = -1so extra data is never pulled. Be careful with doing this with an existing app that relied on$recursivedata.Then, during a find call, use the ‘contain’ query key. For example, on your GroupsController:
This will bring in the User information associated with the group, along with the Image information associated with the users.