Ahh awesome, thats good to know!
Cheers,
Adam
On Feb 25, 6:29 pm, AD7six <[EMAIL PROTECTED]> wrote:
> Adam Royle wrote:
> > If you want to sort on the column as well, I suggest you create a
> > "counter cache". Basically, you store the count of subitems in a field
> > in the main table, which is
Hi AD,
I have seen the "counterQuery" option for hasMany association but do
not know much about it .. Do you have some usage sample of this ??
Cheers
Franck
On Feb 25, 9:29 am, AD7six <[EMAIL PROTECTED]> wrote:
> Adam Royle wrote:
> > If you want to sort on the column as well, I suggest you cre
Adam Royle wrote:
> If you want to sort on the column as well, I suggest you create a
> "counter cache". Basically, you store the count of subitems in a field
> in the main table, which is updated on create/update/delete.
>
> There is even a behaviour that can do this automatically for you.
>
>
I use the finderQuery of the hasMany relation, I call bindModel before
paginate.
Suppose a Customer has many Contract, in paginate :
$finderContract = 'SELECT DISTINCT Contract.customer_id,
COUNT(Contract.id) as contractCount ';
$finderContract .= 'FROM contracts as Contract ';
I use to bindModel again with hasMany and use the filterQuery to
count.
On Feb 25, 8:33 am, Adam Royle <[EMAIL PROTECTED]> wrote:
> If you want to sort on the column as well, I suggest you create a
> "counter cache". Basically, you store the count of subitems in a field
> in the main table, which
If you want to sort on the column as well, I suggest you create a
"counter cache". Basically, you store the count of subitems in a field
in the main table, which is updated on create/update/delete.
There is even a behaviour that can do this automatically for you.
http://bakery.cakephp.org/articl
One of the things about Cake that I'm not so hot about is having to
give up (mostly) writing SQL. For some people, that's a feature, I
guess.
Anyway, don't fight the framework ;-) Do your find() on Posts,
grabbing Comments along with them. When iterating over them in the
view, you can simply do a
This may be silly since there is a better to do this I'm sure, but is
there a way to count the number of items in a subselect on pagination?
Or is there a way to count the number of items that are linked in a
hasMany relationship. i.e. can you output the number of comments that
are associated with