I just tried using Containable:
$this->LocalInfo->Behaviors->attach('Containable');
$this->paginate['LocalInfo'] = array(
'contain' => array('Subcat', 'Cat', 'Location'),
'order' => 'LocalInfo.title'
);
but got these errors:
Warning (512): Model "LocalInfo" is not associated with model
"Subcat" [CORE/cake/libs/model/behaviors/containable.php, line 340]
Warning (512): Model "LocalInfo" is not associated with model
"Cat" [CORE/cake/libs/model/behaviors/containable.php, line 340]
Warning (512): Model "LocalInfo" is not associated with model
"Location" [CORE/cake/libs/model/behaviors/containable.php, line 340]
On Feb 12, 2:54 pm, koala kid <[email protected]> wrote:
> Paul,
>
> I was just trying your bindModel trick on the index function of the
> same controller, but this one uses the Paginator component to make it
> easier for the user to sort through results. However doing this the
> bind doesn't seem to be taking place as I am getting SQL errors. Any
> suggestions?
>
> Warning (512): SQL Error: 1054: Unknown column 'Subcat.cat_id' in
> 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line
> 525]
>
> $sql = "SELECT `Cat`.`id`, `Cat`.`title`, `Cat`.`location_id`,
> `Cat`.`created`, `Cat`.`modified` FROM `cats` AS `Cat` WHERE
> `Subcat`.`cat_id` = `Cat`.`id` "
> $error = "1054: Unknown column 'Subcat.cat_id' in 'where clause'"
>
> $sql = "SELECT `Location`.`id`, `Location`.`city`,
> `Location`.`state`,
> `Location`.`country`, `Location`.`info`, `Location`.`order`,
> `Location`.`meta_url`, `Location`.`meta_title`,
> `Location`.`meta_desc`, `Location`.`meta_tags`, `Location`.`created`,
> `Location`.`modified` FROM `locations` AS `Location` WHERE
> `Cat`.`location_id` = `Location`.`id` "
> $error = "1054: Unknown column 'Cat.location_id' in 'where clause'"
>
> On Feb 12, 11:45 am, koala kid <[email protected]> wrote:
>
> > Paul, sorry for the late reply, I wasn't notified of your response.
> > Your trick worked like a charm, thanks man, I've been scratching my
> > head over this for ages. So it's not just me going crazy then, I am
> > having problems in a few places getting ORM to return my results, as I
> > am newish to Cake I kept thinking I must be doing something wrong, its
> > nice to know I'm not a complete idiot.
>
> > Thanks.
>
> > On Feb 11, 3:41 am, WebbedIT <[email protected]> wrote:
>
> > > Now people keep telling me that I am wrong here, but I have always had
> > > problems with deep belongsTo associations not being fetched with
> > > recursive alone.
>
> > > In your instance LocalInfo belongsTo Subcat which belongsTo Cat which
> > > belongsTo Location and your find recursive stops after the first
> > > belongsTo only finding LocalInfo and Subcat.
>
> > > There are a few things you can do.
>
> > > 1. Force a join from LocalInfo to Cat by doing the following in the
> > > controller before the find
>
> > > $this->LocalInfo->bindModel(array('belongsTo'=>array(
> > > 'Cat'=>array(
> > > 'foreignKey'=>false,
> > > 'type'=>'INNER',
> > > 'conditions'=>array('Subcat.cat_id = Cat.id')
> > > )
> > > )), true);
>
> > > The last condition defaults to true so you dont actually need to pass
> > > it, but if your paginating results needs to be set to true to make the
> > > bind persistent otherwise the bind only exists for the first find that
> > > follows it.
>
> > > If you need also need data from Location you would need to bind that
> > > too as follows:
>
> > > $this->LocalInfo->bindModel(array('belongsTo'=>array(
> > > 'Cat'=>array(
> > > 'foreignKey'=>false,
> > > 'type'=>'INNER',
> > > 'conditions'=>array('Subcat.cat_id = Cat.id')
> > > ),
> > > 'Location'=>array(
> > > 'foreignKey'=>false,
> > > 'type'=>'INNER',
> > > 'conditions'=>array('Cat.location_id = Location.id')
> > > )
> > > )), true);
>
> > > 2. The 2nd option is to use containable, which I use all the time and
> > > is great as long as you're not needing to place any conditions on the
> > > deep tables, in which case you must do the above.
>
> > >http://book.cakephp.org/view/474/Containable
>
> > > HTH
>
> > > Paul.
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