It can be done in one command. I had a similar problem the other day and I 
solved it by initializing the constructor in the Model I wanted this to 
work on and created a VirtualField, and by specifying the $this->alias 
CakePHP could then pick up the association and find the appropriate column. 
In your case I think $this->alias would either return ParentDomain or 
ChildDomain and by doing this it would append the chronicle_id to either 
option. Here is an example of my code block, hope it helps you:

       public function __construct($id = false, $table = null, $ds = null) {
               parent::__construct($id, $table, $ds);

            $this->virtualFields = array(
              'full_name' => "CONCAT(`{$this->alias}`.`firstName`, ' ', 
`{$this->alias}`.`middleName`, ' ', `{$this->alias}`.`lastName`)"
  );
}

Then, in the controller's find function, you should have something like 
this:

        $parentDomains = $this->Domain->ParentDomain->find('list', 
array('fields' => array('full_name'));

In addition, have a look at this - 
http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html


On Sunday, 10 June 2012 23:45:48 UTC-4, Michael wrote:
>
> So I have a table called Domains which has a parent_id allowing the 
> domains to contain a parent/child relationship, the parent being referred 
> to as ParentDomain.
>
> For the case I am working on, the ParentDomain has a variable called 
> chronicle_id. The condition I want to make will get all domains where its 
> ParentDomain.chronicle_id == 1.
>
> I tried to put array("ParentDomain.chronicle_id"=>1) as a condition to my 
> domain find, but id complained because the ParentDomain.chronicle_id was an 
> unknown column.
>
> Is it possible to do this in one command, or will I need to make several 
> hits to the database to make it work?
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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