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

2008-12-03 Thread jsmale

Finally fixed the problem. Stupid me, I was running it on PHP4.
Switched to PHP5 and it's working perfectly.

On Dec 3, 9:09 am, jsmale [EMAIL PROTECTED] wrote:
 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



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

2008-12-03 Thread Adriano Varoli Piazza

On 3 dic, 08:27, jsmale [EMAIL PROTECTED] wrote:
 Finally fixed the problem. Stupid me, I was running it on PHP4.
 Switched to PHP5 and it's working perfectly.


Shouldn't it also be working on PHP 4?

--
Saludos
Adriano
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



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

2008-12-02 Thread jsmale

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



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

2008-12-02 Thread Rob

Look at my last post here 
http://groups.google.com/group/cake-php/browse_thread/thread/b3ff9deff2d1ea1e

You probably need to do your 'save' then set the id from
getLastInsertedId() ...

On Dec 1, 9:12 pm, jsmale [EMAIL PROTECTED] 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



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

2008-12-02 Thread teknoid

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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



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

2008-12-02 Thread jsmale

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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Saving extra fields in the join table (for HABTM models)

2008-10-28 Thread nomex

Hey guys, sorry to bother you again, but i'm spending hours on this
problem and can't find the solution:

teknoid has this nice blog, where he describes his metode so save some
extra data to the HABTM table by binding them as hasMany.

http://teknoid.wordpress.com/2008/09/24/saving-extra-fields-in-the-join-table-for-habtm-models/


i have 3 tables:
users, Companies and CompaniesUser

my code looks like this:

$this-data['CompaniesUser'][0]['company_id'] = '99';
$this-data['CompaniesUser'][0]['status'] = 'disabled';


$this-User-bindModel(array('hasMany'=array('CompaniesUser')));
$this-User-saveAll($this-data)

it saved the user correctly and it saves the company_id and the status
in the companiesUser table, but it didn't insert the user_id from the
new created user. any idea what i'm doing wrong?

thx for your help!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---