mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
新增Relation方法是否存在判断
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
|
use BadMethodCallException;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use think\db\Query;
|
use think\db\Query;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
@@ -567,6 +568,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param Relation $modelRelation 模型关联对象
|
* @param Relation $modelRelation 模型关联对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws BadMethodCallException
|
||||||
*/
|
*/
|
||||||
protected function getRelationData(Relation $modelRelation)
|
protected function getRelationData(Relation $modelRelation)
|
||||||
{
|
{
|
||||||
@@ -574,7 +576,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$value = $this->parent;
|
$value = $this->parent;
|
||||||
} else {
|
} else {
|
||||||
// 首先获取关联数据
|
// 首先获取关联数据
|
||||||
$value = $modelRelation->getRelation();
|
if (method_exists($modelRelation, 'getRelation')) {
|
||||||
|
$value = $modelRelation->getRelation();
|
||||||
|
} else {
|
||||||
|
throw new BadMethodCallException('method not exists:' . get_class($modelRelation) . '-> getRelation');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user