Thursday, January 27, 2011

RE: Join Tables between db

No I am not but I will certainly add that and give it a try.

I manually made my join model since it has custom validation rules so its
finding the file / model (not the autocreated one) since it validates /
returns errors on fail, but never knew of the "with" so I will see how that
play out.

Thanks for the tip.


Dave
-----Original Message-----
From: ShadowCross [mailto:adriano@jps.net]
Sent: Thursday, January 27, 2011 2:04 PM
To: CakePHP
Subject: 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

--
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: