Been trying to make sense of HABTM relationship. Hope someone could
help throw some light on this.
I have the following models defined:
class TblCategory extends AppModel {
var $name = 'TblCategory';
var $hasAndBelongsToMany = array('TblDetail'=>array(
'className' =>
'TblDetail',
'joinTable' =>
'tbl_ad_categories',
'with' =>
'TblAdCategory',
'foreignKey' =>
'tbl_category_id',
'associationForeignKey' => 'tbl_detail_id'
));
}
class TblDetail extends AppModel {
var $name = 'TblDetail';
var $hasAndBelongsToMany = array('TblCategory'=>array(
'className' =>
'TblCategory',
'joinTable' =>
'tbl_ad_categories',
'with' =>
'TblAdCategory',
'foreignKey' =>
'tbl_detail_id',
'associationForeignKey'
=> 'tbl_category_id'
));
}
class TblAdCategory extends AppModel {
var $name = 'TblAdCategory';
var $belongsTo = array('TblDetail','TblCategory');
}
In my controller I have the following statement:
$advertisers = $this->paginate('TblDetail', array
('TblDetail.ap_advertiser LIKE'=>"%".$searchstr."%"));
where $searchstr is merely a value passed in from a form.
When I do a pr($advertisers) it shows the [TblDetail] Array as
expected. But the associated [TblCategory] shows an empty array even
though there is related TblCategory records.
Been trying to figure out where I have gone wrong. How do I get the
associated TblCategory record as well?
Any help is greatly appreciated.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---