Monday, March 24, 2014

Re: $this->field and contain

Any reason you can't use counterCache?


On Monday, March 24, 2014 11:07:46 AM UTC-4, advantage+ wrote:

Can you use / is there a way to read a field and not add in extra relation queries?

 

I have a very simple function to read 1 field and update it by +1

 

public function pageCount($id) {

                $this->id = $id;

                $count = $this->field('view_count', array('id' => $id)) + 1;

                $this->saveField('view_count', $count);

}

 

Right now the full page has 30 querys exectuted.
Removing this call from the controller.

 

$this->User->pageCount($user['User']['id']);

 

And the page queries drop to 23. Odd how a simple call to read 1 field and update by 1 creates 7 queries.

Looking at the extra queries its pulling in related models.

 

I can write a find and use contain => false I suppose but figured I would ask.

 

--
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/d/optout.

No comments: