tighten / parental

Use single table inheritance in your Laravel app
MIT License
1.36k stars 98 forks source link

Eager loading issue :( #73

Closed hexatex closed 1 year ago

hexatex commented 4 years ago

I have a parent model called Category, and two category types, Link & Dynamic. Only one of them has the relationship criteriable()

When I try to load like,

$categories->load('criteria');

I get the error, Call to undefined relationship [criteria] on model [App\Models\Category\Category]' Is eager loading that relationship possible?

Category

class Category extends Model
{
    use Filtered, HasChildren;

    /**
     * @var array
     */
    protected $childTypes = [
        'dynamic' => Dynamic::class,
        'link' => Link::class,
        'regular' => Regular::class,
    ];

    /**
     * @var array
     */
    protected $fillable = [
        'type',
        'name',
    ];

Dynamic

class Dynamic extends Category implements CategoryType, Criteriable
{
    use HasParent;

    /**
     * Criteria
     * @return MorphOne
     */
    public function criteria()
    {
        return $this->morphOne(Criteria::class, 'criteriable');
    }

Link

class Link extends Category implements CategoryType
{
    use HasParent;

    /*
     * No relationships
     */
hexatex commented 4 years ago

I have added

protected $with = ['criteria'];

but that did not work either, no error, just didn't load.

hexatex commented 4 years ago

:,(

mattstauffer commented 1 year ago

Hey friends! The team at Tighten has taken Parental back over and we're re-opening the issue tracker, but to give us a clean slate, I'm going to close all old issues that remain from when Caleb closed the issue tracker in 2020. If this is still an outstanding concern with the latest version of Parental, please feel free to open a new issue referencing this one.

Thank you!