Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasAttributes->isRelation() returns wrongly TRUE when a new style Accessor is present #40966

Closed
jozydapozy opened this issue Feb 11, 2022 · 1 comment

Comments

@jozydapozy
Copy link

jozydapozy commented Feb 11, 2022

  • Laravel Version: 9.0.2
  • PHP Version: 8.0.15

Description:

When calling isRelation() on a model, to test if a certain key is a relation, the function returns wrongly true when a Accessor-method is present.

Steps To Reproduce:

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
 
class User extends Model
{
    protected function myname(): Attribute
    {
        return new Attribute(
            get: fn () => 'some value'
        );
    }
}

And than, somewhere in your application call this

dd($user->isRelation('myname')); // returns TRUE

Since 'myname' is not a relation, but a Accessor, it is expected that isRelation() should return false.

A possible fix would be to do an extra check in the isRelation() method to test if a method is not a Accessor, but I'm not sure what's the best approach to do that.

@jozydapozy
Copy link
Author

Thanks! Awesome! This fixes the issue indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants