Tuesday, December 2, 2008

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

My Join table does have a primary key (http://i35.tinypic.com/
ofozko.jpg
) & all tables are InnoDB to support transactions (http://
i36.tinypic.com/xqfhmx.jpg). However the overall type is MyISAM - is
this a problem? If so, can it be changed?

It would be nice if I could use saveAll() rather than programming the
transaction handling into the controller.

Any hints or examples would be greatly appreciated :)

On Dec 3, 6:11 am, teknoid <teknoid.cake...@gmail.com> wrote:
> Does your join table have a primary key?
>
> If using MySQL are your tables InnoDB? (MyISAM tables do not support
> transactions, so it might look like it's working, but you'll run into
> problems).
>
> On Dec 2, 12:12 am, jsmale <jason.sm...@gmail.com> wrote:
>
> > 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: