1

In the initialize function of OrdersTable.php, I have

$this->hasOne('CurrentReview', [
    'className' => 'Reviews',
    'finder' => 'latest',
    'foreignKey' => 'order_id 
]);

and in ReviewsTable.php, I have

public function findLatest(query $q)
{
    return $q->orderDesc('id')->limit(1);
}

I am trying to get only the latest review associated with the order, but I am only ever able to get the first one.

$order = $this->Orders->get($id, ['contain' => [
    'CurrentReview'
]]);

What am I missing?

I am almost getting what I need with

$order = $this->Orders->get($id, ['contain' => [
    'Reviews' => function ($q) {
        return $q->find('latest');
    }
]]);

but it's inside an array that I don't want

cck
  • 193
  • 1
  • 14
  • Sounds like http://stackoverflow.com/questions/30241975/how-to-limit-contained-associations-per-record-group to me. – ndm Aug 10 '16 at 15:48

0 Answers0