Hi all,
I am having a problem getting data from a model connected to a HABTM
If I have two models, the first being hasMany to the second, then if I
do a find on the second, I can normally access the first models
fields, because a LEFT join is done? However, if the model is
HasAndBelongsToMany then this is not the case??
So, my problem now ---> I have four tables, one called Categories, one
called Cities and the bridging table Categories_Cities
And the fourth table is called Items .... where Categories HasMany
Items.
But when I do a find on Categories_Cities, it is not finding my Items
table, like it would if it was a HasMany relationship.
Cities ----> Categories_City <----- Categories <--- Items
Is that clear?
The last part of my email contains my models:
class Item extends AppModel
{
var $name = 'item';
var $hasOne = array(
'Vote' => array(
'className' => 'Vote',
'foreignKey' => 'item_id'
)
);
class City extends AppModel
{
var $name = 'city';
var $hasMany = array(
'Item' => array(
'className' => 'Item',
'foreignKey' => 'city_id'
)
);
var $hasAndBelongsToMany = array(
'Category' => array(
'className' => 'Category',
'foreignKey' => 'city_id'
)
);
class Category extends AppModel
{
var $name = 'category';
var $hasMany = array(
'Item' => array(
'className' => 'Item',
'foreignKey' => 'category_id'
)
);
var $hasAndBelongsToMany = array(
'City' => array(
'className' => 'City',
'foreignKey' => 'category_id'
)
);
class CategoryCity extends AppModel
{
var $name = 'CategoryCity';
var $useTable = 'categories_cities';
var $belongsTo = array
(
'Category' => array
(
'className' => 'Category',
'foreignKey' => 'id'
),
'City' => array
(
'className' => 'City',
'foreignKey' => 'id'
)
);
}
Andrew
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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