Hi,
-- Thanks for the reply. Would that require me to introduce the field in the database schema? I would like to also include the count in chapters, units and subjects. Would that require a schema change for each of these tables?
Thanks again for your reply.
On Sunday, August 18, 2013 2:14:49 AM UTC-4, Jeremy Burns wrote:
On Sunday, August 18, 2013 2:14:49 AM UTC-4, Jeremy Burns wrote:
counterCache is your friend.Class Outfit
Jeremy Burns
http://www.classoutfit.comOn 17 Aug 2013, at 23:02:51, Nicholas Amon <nichol...@gmail.com> wrote:Hi,I have the following model relationshipsQuestion belongs to ChapterChapter belongs to UnitI want to add a virtual field in the Unit model that counts how many questions a unit has. I tried this:public $virtualFields = array("questionCount" => 'SELECT COUNT(*) FROM questions as Question JOIN chapters as Chapter ON (Question.chapter_id = Chapter.id) JOIN units as Unit ON (Chapter.unit_id = Unit.id)');The problem here is that it returns the same value for all untis. The issue here is that I want the count for each Unit instance. In other words, I would like to add a where clause so that the query becomes something similar to:public $virtualFields = array("questionCount" => 'SELECT COUNT(*) FROM questions as Question JOIN chapters as Chapter ON (Question.chapter_id = Chapter.id) JOIN units as Unit ON (Chapter.unit_id = Unit.id) WHERE Unit.id = CAKE_REPLACE_WITH_CURRENT_ID');How do I get cake to CAKE_REPLACE_WITH_CURRENT_ID to be the ID of the current Unit instance that is being retrieved?I hope I have made my question clear. Thanks in advance.--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com .
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php .
For more options, visit https://groups.google.com/groups/opt_out .
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment