Lighthouse: How to use custom relation

Created on 1 Mar 2019  路  2Comments  路  Source: nuwave/lighthouse

I use laravel medialibrary. In my model, i create method, which return Colleaction

public function colors()
{
        return $this->getMedia('colors');
}

in my scheme i add

colors: [Media] @hasMany(relation: "colors")

sample query

query {
  item {
    name
    colors {
      id
    }
  }
}

getting an error: Method Illuminate\Support\Collection::addEagerConstraints does not exist.

How best to implement custom relation?

question

Most helpful comment

Your colors function doesn't return a relationship, but just a collection. So, your schema should be:

...
colors: [Media!] @method(name: "colors")
...

All 2 comments

Your colors function doesn't return a relationship, but just a collection. So, your schema should be:

...
colors: [Media!] @method(name: "colors")
...

@enzonotario, thanks!

Was this page helpful?
0 / 5 - 0 ratings