Another thing you can do is to add a new field in the Bar model to store the count of associated Foo and let Cake handle its value as explained in this page:
http://book.cakephp.org/view/75/Saving-Your-Data#counterCache-Cache-your-count-490 Andrea On Wed, Jan 28, 2009 at 5:25 PM, brian <bally.z...@gmail.com> wrote: > > I think the quickest way would be to create a database view. > > CREATE VIEW foobar AS SELECT f.id, COUNT(b.id) FROM foo AS f INNER > JOIN bar AS b ON b.foo_id = f.id GROUP BY f.id'; > > $this->Foo->query('SELECT * FROM foobar'); > > Oooh! Wouldn't Cake DBviews be tasty? Cake 2.0, maybe? > > On Wed, Jan 28, 2009 at 10:18 AM, Günther Theilen <thei...@eqi.de> wrote: >> >> Hi, >> >> I've got two models "Foo hasMany Bar". >> What would be the best way to get all entries of Foo and the number of >> according entries in Bar. >> I thought about a find->('all') and a count() in the view but that >> doesn't seem to be very elegant. >> Any hints? >> >> Regards >> Guenther >> >> > >> > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---