mirror of
https://github.com/flarum/core.git
synced 2025-07-26 03:01:22 +02:00
Don't error if trying to serialise a non-existent relationship
This commit is contained in:
@@ -52,6 +52,18 @@ abstract class Serializer extends SerializerAbstract
|
|||||||
*/
|
*/
|
||||||
abstract protected function getDefaultAttributes($model);
|
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.
|
* 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;
|
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}()");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user