eloquence
eloquence copied to clipboard
Logic reversed in getAttribute()
I've just noticed an interesting discrepancy in getAttribute()
between how the CamelCasing
trait works and the original Eloquent Model.
Consider the Eloquent Model function:
public function getAttribute($key)
{
if (array_key_exists($key, $this->attributes) || $this->hasGetMutator($key)) {
return $this->getAttributeValue($key);
}
return $this->getRelationValue($key);
}
Now look at CamelCasing:
public function getAttribute($key)
{
if (method_exists($this, $key)) {
return $this->getRelationValue($key);
}
return parent::getAttribute($this->getSnakeKey($key));
}
Eloquent allows attributes (even read-only ones) precedence over relations. CamelCasing favours relationships first.
It seems to me that following Eloquence's order of preference would be a good idea, so the behaviour is consistent between both.
@valorin cheers! i have a feeling this may have been changed in the core codebase, as I'm fairly certain I duplicated the first bit of it. Something in the back of my mind is saying that I felt it was weird to begin with (placing relations over attributes).
Happy to change this - it should definitely maintain the same behaviour as Eloquent.
any chance this will be updated?
Certainly, soon as I have time.