thinkphp5关联模型改造,超方便

浏览:2980 发布日期:2017/10/10 分类:ThinkPHP5专区 关键字: 关联模型
//广告模型中
class Ad extends App
{
    public $assoc = array(
        'AdPosition' => array(
            'type' => 'belongsTo',##关联模型
            'counterCache' => true##自动统计 每添加一个广告,父级广告位中ad_count自动加1
            //'countWhere' 支持统计条件
            //'foreignKey' 支持自定义外键
            //'where' 支持关联额外条件
        )
    );
##广告位模型中
class AdPosition extends App
{
    public $assoc = array(
        'Ad' => array(
            'type' => 'hasMany',##关联类型
            'deleteWith'=>true,##广告位删除,它下面的广告也删除
        )
    );
模型关联定义关联数组即可,无需按官方定义一个hasmany的function。
在关联查询使用确可以按官方一样的关联查询。

还有更多方便等着你的使用!
http://www.eduaskcms.xin
测试:
http://www.eduaskcms.xin/run
一个开源开发框架,这些功能都已经改造完成。。。


最佳答案
评论( 相关
后面还有条评论,点击查看>>