Limit Results from Association


I’m starting to get my application to work. However, I have this question:

I have a bank account entity with transactions.

I want to retrieve a specific bank account, and retrieve the last 15 transactions.

How can I limit the number of transactions retrieved?

Here’s my code now:

    $bankAccount = $this->BankAccounts->get($id, [
        'contain' => [
            'Transactions' => ['sort' => ['Transactions.created' => 'DESC']]]

I tried putting ‘limit’ => 15 in the Transactions part of the array, but that threw an error.

I do not believe this is possible without building a query manually. Please read this feature request here

1 Like

Thanks, good to know. I’ll just load the transactions separately then.