Monday, December 1, 2008

Id missing when saving extra fields in the join table (for HABTM models)

Hi,

After extensive reading, I've followed teknoid's example (http://
teknoid.wordpress.com/2008/09/24/saving-extra-fields-in-the-join-table-
for-habtm-models/
) on how to save an extra field on a join table.

Just one problem :( Here's the data array being saved:
------------------------------
Array(
[Payment] => Array(
[registry_id] => 10
[name] =>
[email] =>
[message] =>
[method] =>
[amount] => 50
)
[ItemsPayment] => Array(
[0] => Array(
[item_id] => 18
[amount] => 50
)
[1] => Array(
[item_id] => 19
[amount] => 35
)
)
)

Related SQL:
1. START TRANSACTION
2. INSERT INTO `payments`
(`registry_id`,`name`,`email`,`message`,`method`,`amount`) VALUES
(10,'','','','','50')
3. SELECT LAST_INSERT_ID() AS insertID
4. INSERT INTO `items_payments` (`item_id`,`amount`,`payment_id`)
VALUES (18,'50','')
5. INSERT INTO `items_payments` (`item_id`,`amount`,`payment_id`)
VALUES (19,'35','')
6. SELECT LAST_INSERT_ID() AS insertID
7. COMMIT
------------------------------

Problem is the payment_id field isn't being populated with the
insertID.


Related code from controller:
$this->Payment->bindModel(array('hasMany'=>array('ItemsPayment')));
$this->Payment->saveAll($this->data);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: