Re: saving into multiple table with multiple data
How are you saving data in items? (code for controller/view/and model). Would it be possible for you to use HABTM for table 2 and 4 to automate some of the steps? On Dec 8, 9:21 am, ridwan arifandi [EMAIL PROTECTED] wrote: i have 5 tables like these 1). purchases 2). purchase_details - purchase_id - item_id 3). items 4). purchase_item_details - purchase_detail_id - item_detail_id 5). item_details - item_id in an action, i have to do more than one save action. rule 1). save data into purchases 2). get last insert id from table purchases 3). save data into items 4). get last insert id from table items 5). save data into purchase_details with those two variables ( purchase_id item_id ) 6). get last insert id from table purchase_details 7). save data into item_details with item_id 8). get last insert id from table item_details 9). save data into purchase_item_detail with those two variables ( purchase_detail_id item_detail_id ) so.. i get a problem at rule #3... it cannot save, dont know why, i have no error message at my web items table CREATE TABLE IF NOT EXISTS `items` ( `id` int(11) NOT NULL auto_increment, `item_type_id` int(11) NOT NULL, `item_brand_type_id` int(11) NOT NULL, `desc` text NOT NULL, `info` text NOT NULL, `default_price` int(11) NOT NULL, `entry_date` date NOT NULL, `entry_by` int(11) NOT NULL, `update_date` date NOT NULL, `update_by` int(11) NOT NULL, `f_expired` enum('t','f') NOT NULL, `f_return` enum('t','f') NOT NULL, `f_active` enum('t','f') NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; please help me... --~--~-~--~~~---~--~~ 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: saving into multiple table with multiple data
thanks for your reply.. i tried it too, and it cannot work, i used debug($data_item) in temporary_items_controller.php and debug ($data) in model.php, it wasn't empty ( has value ) i dont know, only ITEM model but others can work rightly thanks a lot On Dec 8, 6:00 pm, Milmar [EMAIL PROTECTED] wrote: Try to log what $data_item contains and check if the structure being passed to the model is correct. Then you can try $this-Item-Create($data_item); and; $this-Item-Save($data_item); --~--~-~--~~~---~--~~ 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: saving into multiple table with multiple data
Try to log what $data_item contains and check if the structure being passed to the model is correct. Then you can try $this-Item-Create($data_item); and; $this-Item-Save($data_item); --~--~-~--~~~---~--~~ 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: saving into multiple table with multiple data
here is the code.. now, this function can work normally, but only for ITEM model, i use manual query likle INSERT INTO 'items' VALUES(...). $this-Item-getLastInsertID doesn't work too, so i use msqyl_insert_id ant it works. function finish() { $user_id= $this-Session-Read('user_id'); $date = date('Y-m-d'); $purchase = $this-TemporaryPurchase-findByUserId($user_id); //-- Purchase-// //setting data before save $data_purchase = $purchase['TemporaryPurchase']; $data_purchase['entry_by'] = $user_id; $data_purchase['entry_date']= $date; $data_purchase['f_valid'] = 'f'; unset($data_purchase['id']); //saving data into table $this-Purchase-Create($data_purchase); $this-Purchase-Save($data_purchase); $purchase_id= $this-Purchase-getLastInsertID(); $i = 0; foreach($purchase['TemporaryPurchaseDetail'] as $purchase_detail) : $item = $this-TemporaryItem-findById($purchase_detail ['temporary_item_id']); $purchase_item_details = $this-TemporaryPurchaseItemDetail- findAllByTemporaryPurchaseDetailId($purchase_detail['id']); //-- Item-// //setting data before save $data_item = $item['TemporaryItem']; $data_item['entry_by'] = $user_id; $data_item['entry_date']= $date; $data_item['f_expired'] = 'f'; $data_item['f_return'] = 'f'; $data_item['f_active'] = 'f'; unset($data_item['id']); unset($data_item['user_id']); $this-data['Item'] = $data_item; /*--- the problem goes here */ $this-Item-Create($this-data); $this-Item-Save($this-data); $item_id= $this-Item-getLastInsertID(); / * */ if(!empty($item_id)) : //setting id for next save //-- PurchaseDetail -// //setting data before save $data_purchase_detail = array( 'purchase_id' = $purchase_id, 'item_id' = $item_id, 'quantity' = $purchase_detail['quantity'], ); //saving data into table $this-PurchaseDetail-Create($data_purchase_detail); $this-PurchaseDetail-Save($data_purchase_detail); $purchase_detail_id = $this-PurchaseDetail-getLastInsertID(); $purchase['TemporaryPurchaseDetail'][$i]['TemporaryItem'] = $item ['TemporaryItem']; $purchase['TemporaryPurchaseDetail'][$i] ['TemporaryPurchaseItemDetail'] = $purchase_item_details; $j = 0; foreach($purchase_item_details as $purchase_item_detail) : $item_detail= $this-TemporaryItemDetail-findById ($purchase_item_detail['TemporaryPurchaseItemDetail'] ['temporary_item_detail_id']); $purchase['TemporaryPurchaseDetail'][$i] ['TemporaryPurchaseItemDetail'][$j]['TemporaryItemDetail'] = $item_detail['TemporaryItemDetail']; //-- ItemDetail -// //setting data before save $data_item_detail = $item_detail['TemporaryItemDetail']; $data_item_detail['item_id']= $item_id;
Re: saving into multiple table with multiple data
Maybe you can try a simple test case whose only purpose is to save something in the item table (separate this test function from the finish function.). When you get that to work, it would be easier to debug within the finish function. Also, try looking into HABTM and other built-in cake features that might simplify the code. =) On Dec 8, 8:39 pm, ridwan arifandi [EMAIL PROTECTED] wrote: thanks for your reply.. i tried it too, and it cannot work, i used debug($data_item) in temporary_items_controller.php and debug ($data) in model.php, it wasn't empty ( has value ) i dont know, only ITEM model but others can work rightly thanks a lot On Dec 8, 6:00 pm, Milmar [EMAIL PROTECTED] wrote: Try to log what $data_item contains and check if the structure being passed to the model is correct. Then you can try $this-Item-Create($data_item); and; $this-Item-Save($data_item); --~--~-~--~~~---~--~~ 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: saving into multiple table with multiple data
ridwan arifandi wrote: in an action, i have to do more than one save action. rule 1). save data into purchases 2). get last insert id from table purchases 3). save data into items 4). get last insert id from table items 5). save data into purchase_details with those two variables ( purchase_id item_id ) 6). get last insert id from table purchase_details 7). save data into item_details with item_id 8). get last insert id from table item_details 9). save data into purchase_item_detail with those two variables ( purchase_detail_id item_detail_id ) so.. i get a problem at rule #3... it cannot save, dont know why, i have no error message at my web saveAll()? --~--~-~--~~~---~--~~ 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 into multiple table with multiple data
i have 5 tables like these 1). purchases 2). purchase_details - purchase_id - item_id 3). items 4). purchase_item_details - purchase_detail_id - item_detail_id 5). item_details - item_id in an action, i have to do more than one save action. rule 1). save data into purchases 2). get last insert id from table purchases 3). save data into items 4). get last insert id from table items 5). save data into purchase_details with those two variables ( purchase_id item_id ) 6). get last insert id from table purchase_details 7). save data into item_details with item_id 8). get last insert id from table item_details 9). save data into purchase_item_detail with those two variables ( purchase_detail_id item_detail_id ) so.. i get a problem at rule #3... it cannot save, dont know why, i have no error message at my web items table CREATE TABLE IF NOT EXISTS `items` ( `id` int(11) NOT NULL auto_increment, `item_type_id` int(11) NOT NULL, `item_brand_type_id` int(11) NOT NULL, `desc` text NOT NULL, `info` text NOT NULL, `default_price` int(11) NOT NULL, `entry_date` date NOT NULL, `entry_by` int(11) NOT NULL, `update_date` date NOT NULL, `update_by` int(11) NOT NULL, `f_expired` enum('t','f') NOT NULL, `f_return` enum('t','f') NOT NULL, `f_active` enum('t','f') NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; please help me... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---