I'm twiting

访问统计

free counters

cakephp的counterCache功能

场景:有两张表cabinet(机柜)表和server表。其中cabinet有一个字段叫server_count,用于记录有多少服务器在每个机柜上。

逻辑:每次添加或减少server,我们都需要手动更新server_count的值。通过counterCache,我们可以让cake代劳。只需要在定义我们的server model的时候加上
var $belongsTo = array(
'Cabinet' => array('counterCache' => true)
);

如此,当我们新增或减少server,cake将自动的修改server_count的值。

Share on Facebook

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>