Sorry for the confusing thread. I think I figured out what the
communication gap is. I said "key" meaning PHP associative array key as
in "key" => "value", I didn't mean primary DB key. All my primary keys
in the DB are called "id" and I've never had trouble with Cake
accessing that.

I resolved my problem, using something unexpected, so here is my
solution.

I have a model called Music to represent a CD with generic fields that
also apply to other types of products, a model called MusicDetails
which holds fields specific to Music, and a third model called Person,
to hold (among other things), Conductors. here are the classes, with
two lines marked with comments.

class Music extends Item {
        var $name = 'Music';
        var $belongsTo = array(
                'Detail' =>          // important line #1
                        array('className'       => 'MusicDetail',
                                  'dependent'   => true,
                                  'foreignKey'  => 'DetailRef'),
                );
}


class MusicDetail extends AppModel {
        // important line #2 follows, broken if this says "MusicDetail"
        var $name = 'Detail';

        var $useTable = 'tblMusic';
        var $hasAndBelongsToMany = array(
        'Conductors' =>
                   array('className'  => 'Smn',
                                 'joinTable' => 'joinMusicSmnConductor',
                                 'foreignKey' => 'MusicIDref',
                                 'associationForeignKey' => 'SmnIDref'),
        'Artists' =>
                   array('className'  => 'Smn',
                                 'joinTable' => 'joinMusicSmnArtist',
                                 'foreignKey' => 'MusicIDref',
                                 'associationForeignKey' => 'SmnIDref'),
                );
}

class Smn extends AppModel {
        var $name = 'Smn';
        var $useTable = 'tblSmn';
}

So what I learned is that the PHP *array key* of the $belongsTo of my
Music model must agree with the var $name field of the associated model
MusicDetail.

The symptom you get if you do not have such agreement is not failure to
link in MusicDetail, which is linked ok, but rather the failure to then
go get Conductor data.

I had thought the var $name was redundant and had to duplicate the
class name, but I see it's more complicated than that.


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

Reply via email to