Re: Adding a new counter cache

2014-01-23 Thread euromark
If you want a simple CakePHP only solution: http://www.dereuromark.de/2013/10/29/resetbehavior-and-hazardablebehavior/ you simply create a shell command "counts" or sth and add those 2 lines to re-save all records in a loop $this->Post->Behaviors->load('Tools.Reset', array('fields' => array(

Re: Adding a new counter cache

2014-01-23 Thread Paul Gardner
No .. It will only run through the table once updating all records. On 23 Jan 2014 12:34, "Aurelian Apostol" wrote: > Wouldn't this run an infinte loop? It needs a further WHERE clause maybe > where model_a.model_b_count IS NOT NULL > > marți, 16 martie 2010, 10:28:28 UTC+2, phpMagpie a scris: >>

Re: Adding a new counter cache

2014-01-23 Thread Aurelian Apostol
Wouldn't this run an infinte loop? It needs a further WHERE clause maybe where model_a.model_b_count IS NOT NULL marți, 16 martie 2010, 10:28:28 UTC+2, phpMagpie a scris: > > I would also run a SQl query direct on the database using phpMyAdmin > or the CLI > > UPDATE model_a SET model_a.model_b_c

Re: Adding a new counter cache

2010-03-17 Thread WebbedIT
Nice idea, thanks for that :) 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.co

Re: Adding a new counter cache

2010-03-16 Thread Brenda
Oh, just for grins, decided to try and automate this. I have a Configurations controller where I do some admin stuff for the site, and I added this function: function counterCheck( ) { $counterTemplate = "UPDATE :atable AS :amodel SET :counter = (

Re: Adding a new counter cache

2010-03-16 Thread Brenda
Thanks everyone. I'll go the SQL route. Just wanted to make sure I wasn't missing something obvious! ...Brenda On Mar 16, 4:28 am, WebbedIT wrote: > I would also run a SQl query direct on the database using phpMyAdmin > or the CLI > > UPDATE model_a SET model_a.model_b_count = (SELECT COUNT(mode

Re: Adding a new counter cache

2010-03-16 Thread WebbedIT
I would also run a SQl query direct on the database using phpMyAdmin or the CLI UPDATE model_a SET model_a.model_b_count = (SELECT COUNT(model_b.id) FROM model_b WHERE model_b.model_a_id = model_a.id) HTH Paul Check out the new CakePHP Questions site http://cakeqs.org and help others with thei

Re: Adding a new counter cache

2010-03-15 Thread John Andersen
Your second option sounds correct for me! No need to mess around with PHP when the database and a "little" script can handle it! At least I would use SQL for it :) Enjoy, John On Mar 15, 8:16 pm, Brenda wrote: > I'm upgrading an existing model to include counters for some of the > hasMany rela

Adding a new counter cache

2010-03-15 Thread Brenda
I'm upgrading an existing model to include counters for some of the hasMany relationships. They all start out as zero, even though there are many hasMany records; each record gets updated once a save/delete occurs. Is there any way to tell Cake to go through and update all the counters, so I can g