mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 21:52:34 +08:00
改进多态关联的morphTo方法 如果不传入参数默认用当前定义的方法名作为字段前缀
This commit is contained in:
@@ -1392,8 +1392,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
* @param array $alias 多态别名定义
|
||||
* @return Relation
|
||||
*/
|
||||
public function morphTo($morph, $alias = [])
|
||||
public function morphTo($morph = null, $alias = [])
|
||||
{
|
||||
if (is_null($morph)) {
|
||||
$trace = debug_backtrace(false, 2);
|
||||
$morph = Loader::parseName($trace[1]['function']);
|
||||
}
|
||||
// 记录当前关联信息
|
||||
if (is_array($morph)) {
|
||||
list($foreignKey, $morphType) = $morph;
|
||||
|
||||
Reference in New Issue
Block a user