Monday, March 24, 2014

$this->field and contain

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.

 

No comments: