Hi1 I nave a HABTM relathin table orders,tourists and link table order_tourists. How i can wrote to base using one form?
add.ctp <?php echo $form->create('Order');?> <fieldset> <legend><?php __('Add Order');?></legend> <?php echo $form->input('name'); echo $form->input('sum'); echo $form->input('Tourist.name'); echo $form->input('Tourist.passport_no'); echo $form->input('Tourist.email'); //echo $form->input('Tourist.id'); ?> </fieldset> <?php echo $form->end('Submit');?> in controller function add() { if (!empty($this->data)) { $this->Order->create(); if ($this->Tourist->save($this->data['Tourist'])) { $tourist_id=$this->Tourist->id; $this->data['Order']['tourist_id']=$tourist_id; $this->Order->save($this->data); $this->Session->setFlash(__('The Order has been saved', true)); // $this->redirect(array('action'=>'index')); } else { $this->Session->setFlash(__('The Order could not be saved. Please, try again.', true)); } } } debug info: .... [data] => Array ( [Order] => Array ( [name] => test1 [sum] => test2 [tourist_id] => 7 ) [Tourist] => Array ( [name] => test3 [passport_no] => test4 [email] => test5 ) ) ....... sql 4 INSERT INTO `tourists` (`name`,`passport_no`,`email`) VALUES ('test3','test4','test5') 5 SELECT LAST_INSERT_ID() AS insertID 6 INSERT INTO `orders` (`sum`,`name`) VALUES ('test2','test1') 7 SELECT LAST_INSERT_ID() AS insertID 8 SELECT `OrdersTourist`.`id` FROM `orders_tourists` AS `OrdersTourist` WHERE `OrdersTourist`.`order_id` = 11 9 INSERT INTO `orders_tourists` (`order_id`,`tourist_id`) VALUES (11,'test3'), (11,'test4'), (11,'test5') as you see its write INSERT INTO `orders_tourists` (`order_id`,`tourist_id`) VALUES (11,'test3'), (11,'test4'), (11,'test5') whats wrong? sorry for large mess! and sorry for my english its not my native. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---