core/library/think/model/relation/MorphTo.php

(开头部分) 9KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

namespace think\model\relation;

use think\Exception;
use think\Loader;
use think\Model;
use think\model\Relation;

class MorphTo extends Relation
{
    // 多态字段
    protected $morphKey;
    protected $morphType;
    // 多态别名
    protected $alias;
    protected $relation;

    /**
     * 构造函数
     * @access public
     * @param Model  $parent    上级模型对象
     * @param string $morphType 多态字段名
     * @param string $morphKey  外键名
     * @param array  $alias     多态别名定义
     * @param string $relation  关联名
     */
    public function __construct(Model $parent, $morphType, $morphKey, $alias = [], $relation = null)
    {
        $this->parent    = $parent;
        $this->morphType = $morphType;
        $this->morphKey  = $morphKey;
        $this->alias     = $alias;
        $this->relation  = $relation;
    }

    /**
     * 获取当前的关联模型类的实例
     * @access public
     * @return Model
     */
    public function getModel()
    {
        $morphType = $this->morphType;
        $model     = $this->parseModel($this->parent->$morphType);
        return (new $model);
    }

    /**
     * 延迟获取关联数据
     * @param string   $subRelation 子关联名
后面还有 239 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。