On Sep 18, 12:17 pm, brian <bally.z...@gmail.com> wrote:
> On Fri, Sep 18, 2009 at 9:19 AM, George H <acher...@gmail.com> wrote:
>
> > Hi everyone,
>
> > Been ripping my hair out on this one, have no idea why it's not
> > working. Hopefully someone here can find something wrong with my code.
>
> > I have a model called Regions. There can be main regions, and then
> > there can be subregions that live under the main regions. Each region
> > belongs to a State (another model). Under each region there are
> > Service areas, which is another model. Here is my Regions table:
>
> > CREATE TABLE IF NOT EXISTS `eco_regions` (
> > `id` int(11) NOT NULL AUTO_INCREMENT,
> > `created` datetime NOT NULL,
> > `modified` datetime NOT NULL,
> > `user_id` int(11) NOT NULL,
> > `state_id` int(11) NOT NULL,
> > `parent_id` int(11) NOT NULL,
> > `name` varchar(255) NOT NULL,
> > `status` enum('Live','Deleted') NOT NULL,
> > PRIMARY KEY (`id`)
> > ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
>
> > When I perform the following in my controller:
> > $regionsResult = $this->Region->find('threaded', array(
> > 'conditions' => array(
> > 'Region.state_id' => $stateID
> > ),
> > 'recursive' => -1
> > ));
> > I get an array that has all the regions under that $stateID, along
> > with the children regions under each region, etc.
>
> This is the correct behaviour because your condition states that the
> Region.state_id must be $stateID.
>
> > However, if I do the following:
> > $regionsResult = $this->Region->find('threaded', array(
> > 'conditions' => array(
> > 'Region.id' => $regionID
> > ),
> > 'recursive' => -1
> > ));
> > I just get the region record for $regionID, and *no* children, even
> > though all the children regions show up in the previous controller
> > code. I only want to retrieve the children regions under the selected
> > region, and not for the whole state.
>
> Correct again, because you've limited the result to exactly one record
> by specifying a particular id.
>
>
>
> > My models:
> > class Region extends AppModel {
> > var $name = 'Region';
> > var $order = "Region.name ASC";
> > var $actsAs = array("Containable");
>
> > var $hasMany = array(
> > 'Servicearea' => array(
> > 'className' => 'Servicearea',
> > 'conditions' => '',
> > 'order' => '',
> > 'foreignKey' => 'region_id'
> > )
> > );
>
> > var $belongsTo = array(
> > 'State' => array(
> > 'className' => 'State',
> > 'conditions' => '',
> > 'order' => '',
> > 'foreignKey' => 'state_id'
> > ),
> > 'User' => array(
> > 'className' => 'User',
> > 'conditions' => '',
> > 'order' => '',
> > 'foreignKey' => 'user_id'
> > )
> > );
> > }
>
> > It seems whenever I want to search by Regions.id, *no* children load
> > up, regardless if there's any or not. If I change my conditions to
> > filter by something else, then they all appear!
>
> I'm not sure that you can do this without using lft & rght columns in
> your table. See the example in the manual here:
>
> http://book.cakephp.org/view/812/find-threaded
This might be the way you, brian, want it to work, however, I am in
George's boat. I expected this to pass the conditions to the children
find() calls and build the threaded list based on that. Instead, it
does a simple find('all') with conditions, it doesn't actually do a
threaded find().
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---