Wednesday, June 30, 2010

SaveAll - Correct syntax?

Hi all,

I'm trying to save/update a number of rows from a grid into a table
with a single command. According to the documentation the SaveAll
command should do this. However, I get nothing...

(default) 26 queries took 149 ms Nr Query Error Affected Num. rows
Took (ms)
23 START TRANSACTION 0 1
24 COMMIT

Here's the view...

<?php
//pr($statuses);
$id = 0;
foreach($products as $product) {
echo '<tr>';
echo '<input type="hidden" name="data[Product]['.$id.'][id]"
value="'.$product['Product']['id'].'">';
echo '<td><input type="text" name="data[Product]['.$id.'][upc]"
value="'.$product['Product']['upc'].'" size="12"></td>';
echo '<td><input type="text" name="data[Product]['.$id.'][name]"
value="'.$product['Product']['name'].'" size="45"></td>';
echo '<td><input type="text" name="data[Product]['.$id.'][price]"
value="'.$product['Product']['price'].'" size="5"></td>';
echo '<td><input type="text" name="data[Product]['.$id.'][discount]"
value="'.$product['Product']['discount'].'" size="5"></td>';
echo "\n";
echo '<td><select name="data[Product]['.$id.'][status_id]"
size="1">';
foreach($statuses as $status) {
$checked = '';
if ($status['Status']['id'] == $product['Product']['status_id']) {
$checked = 'selected';
}
echo '<option value="'.$status['Status']['id'].'" '.$checked.'>'.
$status['Status']['name'].'</option>';
}
echo '</select></td>';
echo '</tr>';
echo "\n";
$id++;
}
?>


And the controller...

$this->Product->SaveAll($this->data, array( 'fieldList' =>
array('Product.id', 'Product.upc', 'Product.name',
'Product.status_id', 'Product.price', 'Product.discount')));

And finally my database table...

CREATE TABLE `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`upc` char(12) NOT NULL,
`name` varchar(45) NOT NULL,
`status_id` int(11) NOT NULL DEFAULT '1',
`price` decimal(10,2) DEFAULT NULL,
`discount` decimal(10,2) DEFAULT NULL,
`product_code` varchar(45) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
`created_by` char(36) DEFAULT NULL,
`modified_by` char(36) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `upc_UNIQUE` (`upc`)
)

Any ideas would be much appreciated!!!

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate