Model Association 'chain'

2010-02-24 Thread p_W
I have 4 models, associated like this:

Model_1 has_many Model_2
Model_2 belongs_to Model_1

Model_2 has_many Model_3
Model_3 belongs_to Model_2

Model_3 has_many Model_4
Model_4 belongs_to Model_3

In my controller, when I call `$my_var = $this-Model_1-find('all')`
the results have Model_1 and Model_2 in them, but I would like it to
recurse down through the whole chain...any thoughts?  Should I just do
it manually in a model function?

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


Re: Model Association 'chain'

2010-02-24 Thread John Andersen
Take a look in the CakePHP manual at the Containable behaviour, which
will give you the possibility to specify how deep you want to go in
your relationships when retrieving your data.
http://book.cakephp.org/view/474/Containable

Also it will make your life easier :)
Enjoy,
   John

On Feb 24, 4:32 pm, p_W paulwoolcoc...@gmail.com wrote:
 I have 4 models, associated like this:

 Model_1 has_many Model_2
 Model_2 belongs_to Model_1

 Model_2 has_many Model_3
 Model_3 belongs_to Model_2

 Model_3 has_many Model_4
 Model_4 belongs_to Model_3

 In my controller, when I call `$my_var = $this-Model_1-find('all')`
 the results have Model_1 and Model_2 in them, but I would like it to
 recurse down through the whole chain...any thoughts?  Should I just do
 it manually in a model function?

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


Re: Model Association 'chain'

2010-02-24 Thread WebbedIT
In the case of viewing a record, Containable is very much your
friend.  Saves you so much time.

If paginating deep associations, espcially if you want a condition on
model 3 or 4, then you need to get your head around ad-hoc (forced)
joins.

http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly

Teknoids blog is a must read if you are to get your head around
forcing joins, and you will eventually need his advice on HABTM too,
saved me edless hours of pain.

http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/

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