I have searched to no avail so my apologies if this is covered
elsewhere. I have a HABTM relationship across databases. It appears
the only way to achieve this is using a model for the joining table.
So instead of Project <-> Contact, it's Project -> ContactsProject <-
Contact, like the following:
Projects (Main DB):
var $name = 'Project';
var $hasMany = array(
                'ContactsProject' => array('className' => 'ContactsProject',
                                                        'foreignKey' => 
'project_id',
                                                        'dependent' => false));

ContactsProject (for the joining table in the Main DB):
var $name = 'ContactsProject';
var $useTable = 'contacts_projects';
var $belongsTo = array(
                'Contact' => array('className' => 'Contact',
                                                        'foreignKey' => 
'contact_id'),
                'Project' => array('className' => 'Project',
                                                        'foreignKey' => 
'project_id'));

Contact (Other DB):
var $name = 'Contact';
var $useDbConfig = 'contacts';
var $useTable = 'contact';
var $primaryKey = 'contactID';
var $hasMany = array(
                'ContactsProject' => array('className' => 'ContactsProject',
                                                        'foreignKey' => 
'contactID'));

I have tried with $recursive = 1,2,3,4 in all models and in the
controller. When accessing /projects/view/1000 I receive the
following:

    [Project] => Array
        (
            [id] => 1000
        )
    [ContactsProject] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [contact_id] => 30
                    [project_id] => 1000
                )

            [1] => Array
                (
                    [id] => 4
                    [contact_id] => 17
                    [project_id] => 1000
                )
        )

Any ideas as to the best way for find(), read(), etc. to return
[Contact] in the result array? Am I approaching this all wrong? Thanks
you very much in advance for your help. CakePHP truly has a wonderful
user community.

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

Reply via email to