Recursive HBTM relationship - Problem
Hi, I have problem with ORM (m-n) to relationship. http://farm4.static.flickr.com/3171/2950137747_b098638c67.jpg?v=0 ERD image The table categories is related to itself using m-n relationship. To make this possible I created a new mapping table called as categories_categories. This is the HBTM I came up with --- var $hasAndBelongsToMany = array( 'Category' => array( 'className' => 'Category', 'joinTable' => 'categories_categories', 'foreignKey' => 'parent_category_id', 'associationForeignKey' => 'child_category_id', 'conditions' => '', 'order' => '', 'limit' => '', 'unique' => true, 'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => '' ), 'Category' => array( 'className' => 'Category', 'joinTable' => 'categories_categories', 'foreignKey' => 'child_category_id', 'associationForeignKey' => 'parent_category_id', 'conditions' => '', 'order' => '', 'limit' => '', 'unique' => true, 'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => '' ) ); -- I think I didnt get the relationshp right. And ended up with this error (below). -- Warning (512): SQL Error: 1048: Column 'parent_category_id' cannot be null [CORE/cake/libs/model/datasources/dbo_source.php, line 521] Code | Context $sql= "INSERT INTO `categories_categories` (`parent_category_id`,`child_category_id`) VALUES (NULL,'1')" $error = "1048: Column 'parent_category_id' cannot be null" $out= null $out = null; if ($error) { trigger_error("SQL Error: {$this->error}", E_USER_WARNING); DboSource::showQuery() - CORE/cake/libs/model/datasources/ dbo_source.php, line 521 DboSource::execute() - CORE/cake/libs/model/datasources/ dbo_source.php, line 208 DboSource::fetchAll() - CORE/cake/libs/model/datasources/ dbo_source.php, line 344 DboSource::query() - CORE/cake/libs/model/datasources/dbo_source.php, line 228 DboMysql::insertMulti() - CORE/cake/libs/model/datasources/dbo/ dbo_mysql.php, line 502 Model::__saveMulti() - CORE/cake/libs/model/model.php, line 1254 Model::save() - CORE/cake/libs/model/model.php, line 1180 Scaffold::__scaffoldSave() - CORE/cake/libs/controller/scaffold.php, line 298 Scaffold::__scaffold() - CORE/cake/libs/controller/scaffold.php, line 424 Scaffold::__construct() - CORE/cake/libs/controller/scaffold.php, line 193 Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 248 Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 213 [main] - APP/webroot/index.php, line 90 Query: INSERT INTO `categories_categories` (`parent_category_id`,`child_category_id`) VALUES (NULL,'1') -- My ERD is like this, I have two tables one is categories table and other is the mapping table to make the m-n relationship possible called as categories_categories. -- CREATE TABLE IF NOT EXISTS `categories_categories` ( `id` int(11) NOT NULL auto_increment, `parent_category_id` int(11) NOT NULL, `child_category_id` int(11) NOT NULL, `created` datetime default NULL, `modified` datetime default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- My problem is smilar to the financial example in this link http://www.tdan.com/view-special-features/5400/ Please, Help me with the HBTM relationship Imranullah Mohammed --~--~-~--~~~---~--~~ 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.co
Re: CakePHP - Warning - Cannot modify header information - headers already sent by
Thanks Marcus Now its working. On Oct 16, 4:05 pm, Marcus Silva <[EMAIL PROTECTED]> wrote: > Try removing any hidden character you may have after the php closing > tag (?>). > > Example: > > ?>remove anything after the tag > > Hope it helps > > Cheers > > Marcus > > On Oct 16, 11:31 am, imu <[EMAIL PROTECTED]> wrote: > > > > > > controller file is messages_controller.php > > > > > > class MessagesController extends AppController{ > > var $name = 'Messages'; > > >var $helpers = array ( > > 'Html', > > 'Form', > > 'Time' > > ); > > > function index($id = null ){ > > if (!$id) { > > $this->Session->setFlash('Invalid Topic'); > > $this->redirect(array ( > > 'action' => 'index' > > ), null, true); > > } > > $this->Message->recursive = 1; > > > $messages = $this->Message->find('all', > > array( 'conditions' => array( 'topic_id' => $id ),'order' => > > 'Message.id DESC') ); > > $this->set('topic_id',$id); > > $this->set('messages',$messages); > > } > > > function add($id = null) { > > if (!empty ($this->data)) { > > $this->Message->create(); > > if ($this->Message->save($this->data)) { > > > $this->Session->setFlash('The message has been > > added'); > > $this->redirect(array ( > > 'action' => 'index' > > ), null, true); > >} else { > > $this->Session->setFlash('message posting > > failed. Try again.'); > > } > > } > > $users = $this->Message->User->find('list'); > > $this->set('topic_id',$id); > > $this->set('users',$users); > > } > > > } > > ?> > > > - > > > My view file is messages folders in views as add.ctp > > > - > > > create('Message',array( 'url' => 'add/'. > > $topic_id ));?> > > > > New topic > >> echo $form->input('message_text'); > > echo $form->input('user_id'); > > echo $form->hidden('topic_id',array( 'value' => $topic_id)); > > ?> > > > > end('post a message');?> > > > > echo $html->link('Go back', array('action'=>'index')); > > ?> > > > - > > > When I fill up the add form and submit. > > The data gets inserted into the messages table without any hiccups. > > > But I get an error during redirection back to the index page like this > > > > > > Warning (2): Cannot modify header information - headers already sent > > by (output started at /opt/lampp/htdocs/cake/message_board/app/ > > controllers/messages_controller.php:115) [CORE/cake/libs/controller/ > > controller.php, line 587] > > > Code | Context > > > $status = "Location:http://localhost/cake/message_board/messages"; > > > header - [internal], line ?? > > Controller::header() - CORE/cake/libs/controller/controller.php, line > > 587 > > Controller::redirect(
CakePHP - Warning - Cannot modify header information - headers already sent by
controller file is messages_controller.php Session->setFlash('Invalid Topic'); $this->redirect(array ( 'action' => 'index' ), null, true); } $this->Message->recursive = 1; $messages = $this->Message->find('all', array( 'conditions' => array( 'topic_id' => $id ),'order' => 'Message.id DESC') ); $this->set('topic_id',$id); $this->set('messages',$messages); } function add($id = null) { if (!empty ($this->data)) { $this->Message->create(); if ($this->Message->save($this->data)) { $this->Session->setFlash('The message has been added'); $this->redirect(array ( 'action' => 'index' ), null, true); } else { $this->Session->setFlash('message posting failed. Try again.'); } } $users = $this->Message->User->find('list'); $this->set('topic_id',$id); $this->set('users',$users); } } ?> - My view file is messages folders in views as add.ctp - create('Message',array( 'url' => 'add/'. $topic_id ));?> New topic input('message_text'); echo $form->input('user_id'); echo $form->hidden('topic_id',array( 'value' => $topic_id)); ?> end('post a message');?> link('Go back', array('action'=>'index')); ?> - When I fill up the add form and submit. The data gets inserted into the messages table without any hiccups. But I get an error during redirection back to the index page like this Warning (2): Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/cake/message_board/app/ controllers/messages_controller.php:115) [CORE/cake/libs/controller/ controller.php, line 587] Code | Context $status = "Location: http://localhost/cake/message_board/messages"; header - [internal], line ?? Controller::header() - CORE/cake/libs/controller/controller.php, line 587 Controller::redirect() - CORE/cake/libs/controller/controller.php, line 568 MessagesController::add() - APP/controllers/messages_controller.php, line 54 Object::dispatchMethod() - CORE/cake/libs/object.php, line 116 Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 259 Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 213 [main] - APP/webroot/index.php, line 90 --- The redirection to the index page fails. The parameters supplied in the form in add.ctp was as I expected "messages/add/1" which you can see the below code --- New topic --- Please, help me out with this problem?? Thank you Imranullah Mohammed --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---