Thank you, Brian! I thought I was supposed to use the Controller class
(var $uses), which would have then 'cascaded' down to incorporate the
appropriate Model but, having seen the fix, that seems like some
pretty stupid logic on my part ;)!

Thank you, again. Your suggestion worked perfectly and I'm getting
exactly the results I want/expect. I appreciate it, very much and have
a good rest of your Sunday.

On May 2, 9:06 pm, brian <bally.z...@gmail.com> wrote:
> Try this:
> $allies = $this->Ally->find( 'all' );
>
> On Sat, May 2, 2009 at 10:31 PM, craig.kaminsky
>
>
>
> <craig.kamin...@gmail.com> wrote:
>
> > Hi,
>
> > I'm a CakePHP noob who is converting a site from Fusebox/ColdFusion to
> > CakePHP (1.2.x). Without boring anyone with the domain details, I want
> > to output a list of 'allies' and their associated organizations
> > (belongs to an organization in the model). The problem I am running
> > into is that I cannot get CakePHP to recognize the relationship
> > between Allies and Organizations from a "third-party" controller (the
> > "HomeController").
>
> > Here's my setup:
>
> > MODEL:
> > FILENAME: ally.php
> > class Ally extends AppModel {
>
> >        var $name = 'Ally';
>
> >        //The Associations below have been created with all possible keys,
> > those that are not needed can be removed
> >        var $belongsTo = array(
> >                'Organization' => array(
> >                        'className' => 'Organization',
> >                        'dependent' => true,
> >                        'foreignKey' => 'organization_id'
> >                )
> >        );
> > }
>
> > FILENAME: organization.php
> > class Organization extends AppModel {
>
> >        var $name = 'Organization';
> >        var $displayName = 'name';
>
> >        //The Associations below have been created with all possible keys,
> > those that are not needed can be removed
> >        var $belongsTo = array(
> >                'OrganizationType' => array(
> >                        'className' => 'OrganizationType',
> >                        'foreignKey' => 'organization_type_id'
> >                )
> >        );
>
> >        var $hasMany =  array(
> >                'Ally' => array(
> >                        'className' => 'Ally',
> >                        'foreignKey' => 'organization_id'
> >                )
> >        );
>
> > }
>
> > CONTROLLER:
> > FILENAME: home_controller.php
> > class HomeController extends AppController
> > {
> >        var $name = 'Home';
> >        var $uses = array( 'Allies');
>
> >        function index()
> >        {
> >                $allies = $this->Allies->find( 'all' );
> >                $this->set( 'allies', $allies );
> >        }
>
> > }
>
> > DB:
> > The tables (allies and organizations) are plural and both have a
> > primary key named 'id". The allies table has a column called
> > 'organization_id' to act as a foreign key (MySQL 5 DB).
>
> > RESULTING SQL IN DEBUG OUTPUT:
> > SELECT `Allies`.`id`, `Allies`.`organization_id`, `Allies`.`sfa_href`,
> > `Allies`.`logo`, `Allies`.`overview`, `Allies`.`active` FROM `allies`
> > AS `Allies` WHERE 1 = 1
>
> > Why wouldn't this setup/configuration result in the allies select
> > trying to join the organizations table from the home controller?
>
> > It does work properly when I set it up from the Allies controller in
> > that I see both Ally data and Organization data. I'm just a little
> > stumped as to how to make this work from the HomeController.
>
> > Any help or guidance would be much appreciated.
>
> > Thanks!
> > Craig

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to