You're overwriting array keys. Name the association something
different (but keep the className pointing to the proper model), and
you'll be on your way.

-J.


On Oct 18, 12:05 am, imu <[EMAIL PROTECTED]> wrote:
> 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("<span style = \"color:Red;text-
> align:left\"><b>SQL Error:</b> {$this->error}</span>",
> 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 
> linkhttp://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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to