Friday, September 12, 2014

patchEntity on belongsToMany relationship advice needed

Can someone advise on patchEntity on a belongsToMany relationship?

I have the following code:
$creditIntermediary = $this->CreditIntermediaries->patchEntity($creditIntermediary,$this->request->data['credit_intermediary'], [
'associated' => [
'CreditIntermediaryTypes'
]
]);
The entity, both before and after patching, looks like this:

App\Model\Entity\CreditIntermediary Object
(
    [_properties:protected] => Array
        (
         [id] => 31257
  [credit_intermediary_types] => Array
   (
[0] => App\Model\Entity\CreditIntermediaryType Object
(
[_properties:protected] => Array
(
[id] => 1
[name] => Dealer
[_joinData] => App\Model\Entity\CreditIntermediariesCreditIntermediaryType Object
  (
  [_properties:protected] => Array
                                (
                                         [id] => 337
                                                 [credit_intermediary_id] => 31257
                                                 [credit_intermediary_type_id] => 1
                                                )
                                         )
                           )
    [1] => App\Model\Entity\CreditIntermediaryType Object
(
[_properties:protected] => Array
(
[id] => 2
[name] => Broker
[_joinData] => App\Model\Entity\CreditIntermediariesCreditIntermediaryType Object
  (
  [_properties:protected] => Array
                                (
                                         [id] => 338
                                                 [credit_intermediary_id] => 31257
                                                 [credit_intermediary_type_id] => 2
                                                )
                                         )
                           )
                       )
)
)

The CreditIntermediaryType data come out of the form as follows, for example:

Array
(
    [credit_intermediary] => Array
    (
            [CreditIntermediaryType] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )
     )
)

However, the problem isn't because of the additional form data item (index[2]); regardless of the number of items returned by the form - the same, fewer, or more - it won't patch.

Thanks in advance.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: