On Thu, Sep 23, 2010 at 7:09 AM, Chris <sol...@gmail.com> wrote:
> Hi there!
>
>
> I'm pretty new to CakePHP and I recently met a problem that I actually
> can not resolve by myself, so I would like some help understanding the
> source of the problem.
>
> I have an events table that contains, with others things, a
> 'location_id' field.
> I have a locations table containing a 'country_id' field.
> And I have a countries table that contains some data related to
> specific countries.
>
> Now, what I would like to get, is a page containing data for a
> specific event: it works. But my array looks like this:
>
>
> Array
> (
>    [Event] => Array
>        (
>            [id] => 1
>            [created] => 2010-09-22 23:57:39
>            [modified] => 2010-09-22 23:57:39
>            [name] => Test event
>            [start_date] => 2010-09-23 20:00:00
>            [end_date] => 2010-09-24 03:00:00
>            [location_id] => 1
>        )
>
>    [Location] => Array
>        (
>            [id] => 1
>            [name] => My home
>            [street] => Here street
>            [house_number] => 128
>            [zip_code] => 7000
>            [city] => Mons
>            [country_id] => 1
>        )
> )
>
> I'd like to append a branch related to the country. I thought it could
> be "automagically" did, but I probably made a mistake. For now, in my
> events_controller file, I do this to get the data related to the
> location's country:
>
>
>                        $data['Country'] = 
> ClassRegistry::init('Countries')->find(
>                                'all', array(
>                                'conditions' => 'Countries.id = 
> '.$data['Location']['country_id']
>                                )
>                        );
>                        $data['Country'] = $data['Country'][0]['Countries'];
>
>                        $this->set('data', $data);
>
> But It looks crap and I suppose that a "clean" way to to this exists.
> But I really do not know what to do with that.

As Andrei mentioned, ContainableBehavior will help with that. See here:
http://book.cakephp.org/view/474/Containable

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to