Oh, I'm not quite there after all!

My deepest nested model instance is showing incorrect data. I'll try
to summarise in case anyone can see any obvious mistakes I've made.

I have a model, ContentItem, which has a belongsTo with
ParentContentItem (amongst many other relationships), which is also a
ContentItem.

If I do:

        $this->paginate = array(
            'conditions' => array('ContentItem.id' => array(1, 2, 3)),
            'recursive' => 2
            );

I see all the correct data, something like:

Array
(
    [ContentItem] => Array
        (
            [id] => 333
            [title] => Some stuff
        )

    [ParentContentItem] => Array
        (
            [id] => 3
***         [parent_content_item_id] => 2   <== This should be the id
of the next nested item.
            [title] => Parent Thing
            [ParentContentItem] => Array
                (
***                 [id] => 2               <== Hoorah!
                )
        )
)

However, when I change the paginate to:

        $this->ContentItem->Behaviors->attach('Containable');

        $this->paginate = array(
            'conditions' => array('ContentItem.id' => array(1, 2, 3)),
            'recursive' => 2
            'contain' => array(
                'ParentContentItem' => array(
                    'fields' => array('ParentContentItem.id,
ParentContentItem.parent_content_item_id, ParentContentItem.title),
                    'ParentContentItem' => array(
                        'fields' => array('ParentContentItem.*')
                        )
                    )
                )
            );

the most deeply nested ParentContentItem shows different content, it
gets the data corresponding to the instance with id = 1 (rather than 2
in the example above).

  Can anyone see where I'm going wrong?

  Thanks,

Toby

On Jul 23, 9:17 am, toby1kenobi <[email protected]> wrote:
> Aha, found it! I needed the ContainableBehaviour. In case it helps
> someone else I found this (in addition to the manual) very helpful:
>
> http://teknoid.wordpress.com/2008/09/05/example-of-cakephps-containab...
>
> toby1kenobi wrote:
> > Hi all,
>
> >   Does anyone know if it's possible to specify which fields are
> > returned in a call to paginate, including fields from nested models.
> > Something like:
>
> >         $this->paginate['MyModel']['fields'] = array(
> >             'DISTINCT MyModel.id, MyModel.title,
> >                 MyModelParent.id, MyModelParent.title',
> >                 MyModelParent.MyModelParent.id,
> > MyModelParent.MyModelParent.title');
>
> >   The above doesn't work, and I can't think of an alternative syntax
> > that might.
>
> >   Cheers,
>
> > Toby
>
>
--~--~---------~--~----~------------~-------~--~----~
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