> I want to save related data (create date, update date, comment) for
> HBTM associated tables. Do I have to create my own SQL-Statement to get
> this data or is there already something in cakephp that I could use
> for?
This is one of the first things I ran into and it should _definitely_ be
worked out very clearly into a FAQ/howto/tutorial.
I'm not yet a cake guru so I need to get somewhat more clued in before I
could write something in the wiki myself.
There's no straight in-core cake support for join-table-meta-data (or
whatever you wanna call join tables with 'extra' columns :-)
And unless someone proves me wrong: having your primary key in the join
table set to the two foreign keys will not work out-of-the-box either.
I've submitted a couple of patches to Trac that permit 'array keys'.
Several threads here and web pages handle the subject.
One thing I did was creating a model for the join table too.
In your case this is the companies_members table and your extra model could be
companiesMembers (+companies_members_controller).
I needed to put a:
var $useTable = 'companies_members';
in the model as well plus a:
$belongsTo to one or both of the other tables (companies and/or members).
Then define $hasMany=array('companiesMembers') in e.g. your companies model.
In your controllers you need to query with recursion, e.g. for the index:
$this->set('companies', $this->$iam->findAll(NULL,NULL,NULL,NULL,NULL, 2));
And for view:
// read() will not do: no recursion, but...
// remember to pass query conditions as the first arg to find()
// null will put "WHERE 1 = 1" in the query
$r = $this->$iam->find('"Company"."id" = '.$id, NULL, NULL, 2);
$this->set('company', $r);
This seems the close to what others are saying too.
However, anyone, feel free to correct me :-) Or better eleborate on the subject
and in the process create a useful manual/wiki section.
Another solution is to put this into your companies model:
var $hasAndBelongsToMany = array(
'Members' => array(
'joinTable' => 'companies_members',
)
);
(and the likewise for members).
However, this will not fetch any extra columns from your join table AFAIK.
Albert
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---