如何在cakephp中的模型中创建归属关联 [英] How create belonge assocation in models in cakephp
本文介绍了如何在cakephp中的模型中创建归属关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Cakephp框架,我的关联有问题。
如何创建蛋糕php中模型中的关联。
当我在模型中使用归属和hasMany时。
I use Cakephp framework, and I have problem with my association. How create belong to association in models in cake php. When I use belongto and hasMany in my model.
我可以找到示例模型来查看此示例吗?
Can I find sample model to view this example?
推荐答案
简单的归属关系:
Simple belongsTo association:
<?php
class Profile extends AppModel {
var $name = 'Profile';
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'
)
);
}
?>
简单hasMany关联:
Simple hasMany association:
<?php
class User extends AppModel {
var $name = 'User';
var $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'user_id',
'conditions' => array('Comment.status' => '1'),
'order' => 'Comment.created DESC',
'limit' => '5',
'dependent'=> true
)
);
}
?>
有关关联的更多具体信息,请参见 CakePHP书。
More specific information about associations is in the CakePHP Book.
这篇关于如何在cakephp中的模型中创建归属关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文