In a habtm-Association get only the user's own entities


I have a habtm-Association, Chatrooms|Users|Chatrooms_Users. Now I want to extend the ChatroomsTable with a function like findMyOwnChatroom(), which only loads the Chatrooms, the user X is signed in. Furthermore, I’m using CRUD and RelatedModels.

I don’t know how to get started with this task.

Thanks in advance!

look at this, i found it at

look for it at “Creating a finder method” subtitle
it seems waht you want to do

public function findTagged(Query $query, array $options)
    return $this->find()
        ->matching('Tags', function ($q) use ($options) {
            if (empty($options['tags'])) {
                return $q->where(['Tags.title IS' => null]);
            return $q->where(['Tags.title IN' => $options['tags']]);

insted of bookmarks and tags, you change them for Users and Classrooms


exactly! I didn’t found this in the manual. Sometimes you search for the wrong terms. After a bit reading, here is my fully working solution regarding the Controller:

$data = $this->Chatrooms->find('OwnChatrooms', ['user_id' => $this->Auth->user('id')]);

Regarding the Model, I’ve just customized the conditions.

Many thanks!