Thursday, January 27, 2011

Re: Join Tables between db

Dave:

Are you using the "with" key when you define your HABTM associations
in both sides of the model? The "with" key forces CakePHP to use a
specific model for the joinTable instead of autocreating one

Example:


category.php:
class Category extends AppModel {
var $useDbConfig = 'resources';

var $hasAndBelongsToMany = array(
'Post' => array(
'className' => 'Post',
'joinTable' => 'categories_posts',
'with' => 'CategoryPost'
...
)
);
}

category_post.php:
class CategoryPost extends AppModel {
var $useDbConfig = 'default';

...
}

post.php:
class Post extends AppModel {
var $useDbConfig = 'default';

var $hasAndBelongsToMany = array(
'Category' => array(
'className' => 'Category',
'joinTable' => 'categories_posts',
'with' => 'CategoryPost'
...
)
);
...
}

See: http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: