Paste your add/edit view code please.

On 19 abr, 15:33, jackgoh <[email protected]> wrote:
> Hi,
>
> Model:
> // Stock model
> //======================
> class Stock extends AppModel
> {
>         var $name = 'Stocks';
>         var $belongsTo = array(
>                         'Category' => array( 'className' => 'Category',
>                         'conditions' => array('Category.id = category_id'),
>                         )
>         );
>
>          var $hasOne = array('StockDetail' => array( 'className'     =>
> 'StockDetail' ));
>
> }
>
> // StockDetail model
> //======================
> class StockDetail extends AppModel
> {
>         var $name = 'Stock_details';
>         var $belongsTo = array(
>                                           'Stock' => array(  'className' =>
> 'Stock',                                                                      
>    'foreignKey' => '',
> 'conditions' => array('Stock.id = stock_id')
>                                 )
>         );
>
> }
>
> // Stock Controller
> //==================
> function edit($id = null) {
>                 $this->Stock->id = $id;
>                 $catergorys = $this->Stock->Category->find('list',
> array(                                                  'fields' =>
> array('id','combined_shortname'),                                             
>           'conditions' => array('status'
> => 'A')                                                      )
>                         );
>                 $this->set(compact(catergorys));
>                 if (empty($this->data)) {
>                         $this->data = $this->Stock->find( array('Stock.id' => 
>  $this->Stock->id ));
>
>                 } else {
>                         $this->Stock->save($this->data['Stock']);
>                         $this->StockDetail->save($this->data['StockDetail']);
>                         $this->Session->setFlash('Your post has been 
> updated.');
>                                // add redirect here...
>                 }
>         }
>
> Everything goes fine to display the data in Viewe, but it is not
> working when update the record, the data in StockDetail table is not
> updated, the record is ONLY updated in Stock table.
>
> I tried saveAll(), but it insert a new record for Stock Only. I tried
> $this->StockDetail->save($this->data)...
>
> Thanks for helping me.
>
> Best regards.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to