I am trying to get the name of the child Locations from my Domain
controller.

Here is the domain model:

class Domain extends AppModel {
    var $name = 'Domain';
    var $actsAs = array('Tree');
    var $displayField = 'name';

    var $belongsTo = array(
        'ParentDomain' => array(
            'className' => 'Domain',
            'foreignKey' => 'parent_id'
        ),
            'ConfirmedUser' => array(
                'className' => 'User',
                'foreignKey' => 'confirmed_id'
            ),
         );

    var $hasMany = array(
            'ChildLocations' => array(
                'className' => 'DomainsLocation',
                  'foreignKey' => 'domain_id'
            ),
            'ChildDomains' => array(
                'className' => 'Domain',
                  'foreignKey' => 'parent_id'
            ),
        );
}


This is my Location model:
class Location extends AppModel {
    var $name = 'Location';
    var $actsAs = array('Tree');
    var $displayField = 'name';

    var $belongsTo = array(
        'ParentLocation' => array(
            'className' => 'Location',
            'foreignKey' => 'parent_id'
        ),
            'ConfirmedUser' => array(
                'className' => 'User',
                'foreignKey' => 'confirmed_id'
            ),
         );

    var $hasMany = array(
            'ChildLocation' => array(
                'className' => 'Location',
                  'foreignKey' => 'parent_id'
            ),
            'ParentDomains' => array(
                'className' => 'DomainsLocation',
                  'foreignKey' => 'location_id'
            ),
        );
}


And this is the Join table for the two:

class DomainsLocation extends AppModel {
    var $name = 'DomainsLocation';
    var $belongsTo = array('Domain', 'Location');
}


So I am trying to get to the name of the Location that has been assigned to
the Domain. This is the find command that I am using in my controller:

$domainInfo = $this->Domain->find('first', array(
'conditions'=>array('Domain.id' => $domainId) ) );


This is what I get when I print the results of $domainInfo:

Array
(
    [0] => Array
        (
            [Domain] => Array
                (
                    [name] => Prime
                    [parent_id] =>
                    [description] => This is the global domain
                    [confirmed_id] => 1
                    [type] => 0
                    [modified] => 2010-09-22 15:17:13
                    [id] => 1
                )

            [ChildLocations] => Array
                (
                    [0] => Array
                        (
                            [id] => 0
                            [domain_id] => 1
                            [location_id] => 2
                            [created] => 2010-09-28 15:29:33
                            [modified] => 2010-09-28 15:29:33
                        )

                )

            [ChildDomains] => Array
                (
                    [0] => Array
                        (
                            [id] => 6
                            [parent_id] => 1
                            [lft] => 2
                            [rght] => 5
                            [confirmed_id] =>
                            [name] => United Kingdom
                            [type] => 1
                            [description] => This domain contains all
of the United Kingdom.
                            [created] => 2010-09-17 04:21:18
                            [modified] => 2010-09-22 15:17:13
                        )

                )

            [children] => Array
                (
                )

        )

)


As you can see, I am getting the location_id but I am not getting the name
of that location and I do not want to have to do a separate search for each
location. Any idea what I am doing wrong? Thanks.


~Michael

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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