mariaczi
(Marekurbanowicz)
1
Hi!
Is in Yii behavior or any like something in cakePHP, which auto update counter record in HAS_MANY record?
I have a lot relation in my DB, and in a lot of cases I need fast access to counter how much related records has my record.
I want to always when user will create or delete related records, counter fields in related records will be auto updated.
In cakePHP I was using so simple mechanism. I had only to write in model something like ‘countercache’ and this was enough.
Is in Yii simple,fast way to get it?
zaccaria
(Matteo Falsitta)
2
As far as I know, there is nothing of similar.
You can create a stat relation for retrive the number of related record. Each time will be a new query, so it will be always updated.
zaccaria
(Matteo Falsitta)
4
Take a look at the documenetation of CStatRelation.
It has the same interface of a relation, and you can build the query you need.
Then on each model you can call $model->statRelationName and retrive what you need.