k1low / has_no
CakePHP 的简单绑定模型实践插件。
3.0.1
2015-10-30 03:07 UTC
Requires
Requires (Dev)
- phpunit/phpunit: 3.7.*
README
此插件支持以下绑定模型实践。
在模型文件中烘焙并编写绑定属性。全部解除绑定模型()。绑定模型()您想要的。
功能
- 通过 Model::belongsTo, Model::hasOne, Model::hasMany, Model::hasAndBelongsToMany 解除模型的所有绑定模型()。
- 通过 Model::belongsTo, Model::hasOne, Model::hasMany, Model::hasAndBelongsToMany 提供 has(), hasAll() 简单绑定模型方法。
!!!!!注意!!!!!
HasNo >= 3.x
基于 Containable
HasNo 2.x
基于属性修改
用法
将以下代码添加到您想要解除所有绑定模型的任何模型中(例如 Post
模型)。
<?php
class Post extends Model {
public $actsAs = array('HasNo.HasNo');
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'post_id',
'dependent' => false,
)
);
public $hasAndBelongsToMany = array(
'Tag' => array(
'className' => 'Tag',
'joinTable' => 'posts_tags',
'foreignKey' => 'post_id',
'associationForeignKey' => 'tag_id',
'unique' => true,
)
);
}
如果您想使用模型的绑定属性,请使用方法 $this->Post->has('Comment')
, $this->Post->has(array('Comment', 'Tag'))
或 $this->Post->hasAll()
.
许可证
MIT 许可证下