Randy Hall
Randy Hall

Reputation: 8137

CakePHP 3.x Find records from current user only with paginate

This seems like a thing that is probably super easy in CakePHP, but I cannot find a clear example.

I would think this works in my controller:

public function index()
{
    $this->paginate = [
        'where' => ['user_id' => $this->Auth->user('id')],
        'contain' => ['Users']
    ];
    $slates = $this->paginate($this->Slates);

    $this->set(compact('slates'));
    $this->set('_serialize', ['slates']);
}

But I always get the full collection back. I am most definitely logged in, I have two unique users, I have created records with each of them.

Upvotes: 0

Views: 58

Answers (1)

yBrodsky
yBrodsky

Reputation: 5041

Change where to conditions. Couldnt find a reference in the docs.

$this->paginate = [
        'conditions' => ['user_id' => $this->Auth->user('id')],
        'contain' => ['Users']
    ];

Upvotes: 3

Related Questions