Tuesday, June 22, 2010

Re: single find query involving HABTM and hasOne

On Tue, Jun 22, 2010 at 4:31 PM, jason001 <jason.deyalsingh@gmail.com> wrote:
>
> Ok i just gave this a try, however i don't think i'm doing it right, i added
>
> "var $actsAs = array('Containable');"
>
> to my app_model.php, which seems to work, however when i run a find like
> this:
>
> this->set('data',
>                        $this->Customer->find('first',
>                                array(
>                                        'conditions'=> array('Customer.id'=>$id),
>                                        'contain'=>array('Phone')
>                                        )
>                                )
>                );
>
> i get data like this:
>
> Array
> (
>    [Customer] => Array
>        (
>            [id] => 1
>            [firstname] => bob
>            [lastname] => bobly
>        )
>
>    [Phone] => Array
>        (
>            [0] => Array
>                (
>                    [id] => 1
>                    [number] => 5555555
>                    [phonetype_id] => 2
>                    [CustomersPhone] => Array
>                        (
>                            [customer_id] => 1
>                            [phone_id] => 1
>                            [id] => 1
>                        )
>
>                )
>
>        )
>
> )
>
>
> which actually is pretty kool since i can get customer and phone / address /
> whatever else i put in that 'contain' array (very neat,will use that
> later!), however it does not give me the descriptive text for my phonetypes
> and details the habtm table which i won't really use.

But you didn't specify that you want the PhoneType records. When using
Containable, the normal recursive is ignored. That is, the behavior
takes care of that. Anything not specified will not be fetched. Try
this:

'contain' => array(
'Phone' => array(
'PhoneType'
)
)

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 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: