cakePhp中的外键定义:延迟加载? [英] Foreign key definition in cakePhp: Lazy loading?

查看:59
本文介绍了cakePhp中的外键定义:延迟加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用cakePhp制作一个小型网站.我定义了表之间的关系,我想知道:那些相关数据每次都会加载吗?因为根据当前视图,将永远不会使用某些链接表,实际上每次都会查询它们.

I'm starting to use cakePhp to make a small website. I defined relationship between table, and I want to know: will those related data loaded every time? Because depending of the current view, some linked table will never be used, and actually they are queried every time.

这给我们带来了巨大的代价,不是吗?

It's a big cost for what it brings to us, no?

那么,如何建立这种关系并仅在需要时才激活它?某种惰性加载仅在需要时才加载相关表吗?

So how to have this kind of relationship and activate it only when we need it? Some kind of lazy loading which loads the related table only if I need it?

推荐答案

在您运行查询之前,Cake可以取消绑定不需要的模型.

Cake facilates to unbind your non require model befire you run your query.

$this->unbindModel(array($relation => $model));

$ relation-是您与其他模型的关系.

$relation - Is your relation with your other model.

$ model-型号名称.

$model - Model Name.

eg: $this->Library->unbindModel(array('belongsTo' => array('Membership'),),false);

http://bakery.cakephp.org/articles/cornernote/2006/12/10/unbindall

这篇关于cakePhp中的外键定义:延迟加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆