Friday, December 26, 2008

Re: Containable behavior not working as expected

Hi Adam,

The SQL being executed:

SELECT `Paper`.`title`, `Paper`.`id`, `Paper`.`created`,
`Volume`.`id`, `Volume`.`title`, `Volume`.`number` FROM `papers` AS
`Paper` LEFT JOIN `volumes` AS `Volume` ON (`Paper`.`volume_id` =
`Volume`.`id`) WHERE `Paper`.`id` = 20 AND `Paper`.`is_deleted` != 1
ORDER BY `weight` ASC LIMIT 1

Volume, Paper and User all have $actsAs = array('Containable');

Cheers,
Aidan

On Dec 26, 2:50 pm, Adam Royle <a...@sleekgeek.com.au> wrote:
> Admittedly I skimmed through your post, but what sql is executed? Are
> sure you sure you've attached the Containable behavior to your model?
>
> Cheers,
> Adam
>
> On Dec 26, 1:28 pm, Aidan Lister <aidanlis...@gmail.com> wrote:
>
>
>
> > I'm having trouble with the Containable behavior.
>
> > My first query,
> > <?php
> > $this->Controller->Paper->recursive = 3;
> > $this->Controller->Paper->Volume->unbindModel(array('hasMany' => array
> > ('Paper')));
> > $data = $this->Controller->Paper->find('first', array(
> >             'conditions' => array('Paper.id' => $id)));
> > debug($data);
> > ?>
>
> > Returns the following information:
>
> > <pre>
> > html/controllers/components/generate.php (line 185)
> > Array
> > (
> >     [Paper] => Array
> >         (
> >             [id] => 1
> >             [weight] => 4
> >             [volume_id] => 1
> >             [user_id] =>
> >             [slug] => xx
> >             [is_deleted] => 0
> >             [is_published] => 1
> >             [is_doisubmitted] => 1
> >             [created] => 2000-01-01 00:00:00
> >             [modified] => 2008-12-26 14:05:01
> >             [deleted] =>
> >             [published] =>
> >             [htmlgenerated] => 2008-12-26 14:05:01
> >             [pdfgenerated] => 2008-12-26 13:44:41
> >             [doisubmitted] => 2008-12-26 13:45:08
> >             [legacy_key] => ailleres
> >             [title] => xxx
> >             [titleabbrev] => xxx
> >             [keywords] => xxx
> >         )
>
> >     [Volume] => Array
> >         (
> >             [id] => 1
> >             [created] => 2008-12-11 20:11:42
> >             [modified] => 2008-12-21 22:48:52
> >             [published] => 0000-00-00 00:00:00
> >             [is_published] => 1
> >             [type] => Normal
> >             [title] => xx
> >             [number] => 01
> >             [year] => 2000
> >             [blurb] =>
> >             [User] => Array
> >                 (
> >                     [0] => Array
> >                         (
> >                             [id] => 2
> >                             [editor_id] => 81
> >                             [group_id] => 4
> >                             [is_deleted] => 0
> >                             [type] => Individual
> >                             [created] => 2008-11-26 00:07:53
> >                             [modified] => 2008-12-18 12:01:47
> >                             [deleted] => 0000-00-00 00:00:00
> >                             [name] => yyy
> >                             [network] =>
> >                             [UsersVolume] => Array
> >                                 (
> >                                     [id] => 3
> >                                     [user_id] => 2
> >                                     [volume_id] => 1
> >                                     [weight] => 100
> >                                 )
>
> >                            ...
>
> >                         )
>
> >                 )
>
> >         )
>
> >     [User] => Array
> >         (
> >         )
> >   ...
> > )
> > </pre>
>
> > As you can see, The relationship Volume->User is working as expected,
> > and any HABTM Users are returned with the Volume.
>
> > Attempting to replicate this with Containable however, I can't get any
> > User information.
>
> > <?php
> >         $data = $this->Controller->Paper->find('first', array(
> >             'conditions' => array('Paper.id' => $id),
> >             'fields' => array('title', 'id', 'created'),
> >             'contain' => array(
> >                 'Volume' => array(
> >                     'fields' => array('id', 'title', 'number'),
> >                     'User' => array(
> >                         'order' => 'UsersVolume.weight ASC',
> >                         'fields' => array('id', 'name'),
> >                 )))));
> >         debug($data);
> > ?>
>
> > The output is:
>
> > <pre>
> > html/controllers/components/generate.php (line 196)
> > Array
> > (
> >     [Paper] => Array
> >         (
> >             [title] => xxx
> >             [id] => 1
> >             [created] => 2000-01-01 00:00:00
> >         )
>
> >     [Volume] => Array
> >         (
> >             [id] => 1
> >             [title] => yyy
> >             [number] => 01
> >         )
>
> > )
> > </pre>
>
> > I'm sure it's something simple ... I would appreciate any help.
>
> > Thanks,
> > Aidan
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: