Hi all,
$hasAndBelongsToMany associations will fetch the fields of the
associated tables, but will not fetch the fields of the joinTable
ifself.

joinTable:
CREATE TABLE `my_keyword` (
        `userId` int(10) unsigned NOT NULL default '0',
        `keywordId` int(10) unsigned NOT NULL default '0',
        `addTime` int(10) unsigned NOT NULL default '0',
        `categoryId` smallint(6) NOT NULL default '40',
        PRIMARY KEY  (`userId`,`keywordId`)
);

Here's my code:

class Keyword extends AppModel {
        var $name = 'Keyword';
        var $useTable = 'cms_keyword';
        var $primaryKey = 'keywordId';
        var $hasAndBelongsToMany = array(
                'User' => array(
                        'className' => 'User',
                        'joinTable' => 'my_keyword',
                        'foreignKey' => 'keywordId',
                        'associationForeignKey' => 'userId',
                        'uniq' => true
                )
        );
}

class User extends AppModel {
        var $name = 'User';
        var $useTable = 'user';
        var $primaryKey = 'userId';
        var $belongsTo = array(
                'UserKeyword' => array(
                        'className' => 'UserKeyword',
                        'foreignKey' => 'userId'
                )
        );
}

class KeywordsController extends AppController {
        var $name = 'Keywords';
        var $recursive = 2;

        function index() {
                $k = $this->Keyword->read(null, 7);
                var_dump($k); // This will output an array with 'User' and
'Keyword', but no fields about the 'joinTable' (my_keyword), but I
also need the fields of my_keyword: addTime & categoryId.
        }
}

How can I fetch the fields of the 'joinTable' with
$hasAndBelongsToMany associations?

Thanks :)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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