mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
Don't error if trying to serialise a non-existent relationship
This commit is contained in:
parent
86811c6508
commit
81170980e0
|
@ -52,6 +52,18 @@ abstract class Serializer extends SerializerAbstract
|
|||
*/
|
||||
abstract protected function getDefaultAttributes($model);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getRelationshipFromMethod($name)
|
||||
{
|
||||
if (isset(static::$relationMethods[$name])) {
|
||||
return call_user_func(static::$relationMethods[$name], $this);
|
||||
}
|
||||
|
||||
return parent::getRelationshipFromMethod($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a closure that returns a Collection/Resource representing a relation.
|
||||
*
|
||||
|
@ -154,25 +166,4 @@ abstract class Serializer extends SerializerAbstract
|
|||
{
|
||||
static::$relationMethods[get_called_class()][$name] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for and execute custom relationships.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (isset(static::$relationMethods[$method])) {
|
||||
array_unshift($parameters, $this);
|
||||
|
||||
return call_user_func_array(static::$relationMethods[$method], $parameters);
|
||||
}
|
||||
|
||||
$className = get_class($this);
|
||||
|
||||
throw new BadMethodCallException("Call to undefined method {$className}::{$method}()");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user