staudenmeir / eloquent-eager-limit-x-laravel-adjacency-list

Merge of staudenmeir/eloquent-eager-limit and staudenmeir/laravel-adjacency-list
MIT License
14 stars 1 forks source link

BadMethodCallException Call to undefined method GeneaLabs\LaravelModelCaching\CachedBuilder::groupLimit(). #2

Closed loveshiun closed 3 months ago

loveshiun commented 3 months ago

Error BadMethodCallException Call to undefined method GeneaLabs\LaravelModelCaching\CachedBuilder::groupLimit(). occurred when using eager limit.

packages


class Node extends Model
{
    use \GeneaLabs\LaravelModelCaching\Traits\Cachable;
    use \Staudenmeir\EloquentEagerLimitXLaravelAdjacencyList\Eloquent\HasEagerLimitAndGraphRelationships;

    public function names() {
        return $this->morphMany(Name::class, "morphname");
    }

    public function simpleNames() {
        return $this->hasMany(SimpleNames::class);
    }

    public function hasRecursiveRelationshipsNames() {
        // the HasRecursiveRelationshipsNames class includes `use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;`
        return $this->hasMany(HasRecursiveRelationshipsNames::class);
    }
}
$relationship = "names"; // or "simpleNames", "hasRecursiveRelationshipsNames", ...
Node::with([$relationship => function($query) {
    $query->limit(1);
}])->where("id", "<", 10)->get();

Some relations seem to be working correctly, while others have errors.

BadMethodCallException  Call to undefined method Staudenmeir\LaravelAdjacencyList\Eloquent\Builder::groupLimit().
BadMethodCallException  Call to undefined method GeneaLabs\LaravelModelCaching\CachedBuilder::groupLimit().

Is this related to the mentioned Limitations, or is it just not directly compatible with other packages (laravel-model-caching)?

staudenmeir commented 3 months ago

Hi @loveshiun,

$relationship = "names"; // or "simpleNames", "hasRecursiveRelationshipsNames", ...

Some relations seem to be working correctly, while others have errors.

Which relationships are working and which aren't?

loveshiun commented 3 months ago
staudenmeir commented 3 months ago

The related models also need to use the HasEagerLimit trait. In the case of HasRecursiveRelationshipsNames, replace the HasRecursiveRelationships trait with HasEagerLimitAndRecursiveRelationships.

loveshiun commented 3 months ago

Resolved after using HasEagerLimitAndRecursiveRelationships in related models.

Thank you.