0

In cakePHP 1.3 we used this method to set the association limit records

'BuyRate' => array(
            'className' => 'Rate',
            'foreignKey' => 'currency_id',
            'dependent' => true,
            'conditions' => array('BuyRate.sale_method_id' => '1', 'BuyRate.payment_method_id' => '3'),         
            'order' => array('BuyRate.id'=>'DESC'), 
            'limit' => '1'      
            
            ),

Now in CakePHP 4, we are using the following method to set the limit in records but the association limit did not set.

 $this->hasMany('SellRate', [
            'className' => 'Rates',
            'foreignKey' => 'currency_id',
            'dependent' => true,
            'conditions' => array('SellRate.sale_method_id' => '2'),
            'propertyName' => 'sell_rate',
    'limit' => 1


        ]);

How can I set the records limit in CakePHP 4 new version???

Subtain
  • 1
  • 2
  • what happens instead, is there any error? and did you check the official docs? – jasie Mar 02 '22 at 14:34
  • 1
    Does this answer your question? [How to limit contained associations per record/group?](https://stackoverflow.com/questions/30241975/how-to-limit-contained-associations-per-record-group) – jasie Mar 02 '22 at 14:42
  • ``` 'sell_rate' => [ (int) 0 => object(App\Model\Entity\Rate) id:4 { }, (int) 1 => object(App\Model\Entity\Rate) id:7 { }, ] 'buy_rate' => [ (int) 0 => object(App\Model\Entity\Rate) id:10 { }, (int) 1 => object(App\Model\Entity\Rate) id:13 { }, ] ``` i have these two entities in a relationship buy rate and sale rate i want to limit only one record in buy rate association array return back. – Subtain Mar 03 '22 at 08:48

0 Answers0