staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

hasManyDeepFromRelations Does not use with the 'wheres' of the first #161

Closed sbc640964 closed 2 years ago

sbc640964 commented 2 years ago

I have two functions that return relationship - 1:records 2:data For the first time I added wheres inside the function

public function records()
{
    return $this->hasMenyDeep(...).where(...);
}

public function data()
{
    return $this->hasMany(Data::class);
}

When I use with hasManyDeepFromRelations I get a query that does not include the queries of the records function:

return hasManyDeepFromRelations(
    $this->records(),
    (new Record())->data()
);
staudenmeir commented 2 years ago

hasManyDeepFromRelations() does not yet apply constraints, you need to add them manually for now:

return hasManyDeepFromRelations(
    $this->records(),
    (new Record())->data()
)->where(...);
sbc640964 commented 2 years ago

@staudenmeir Thanks. Too bad, why not really?

staudenmeir commented 2 years ago

It's quite complex to cover all the possible cases, but I'm working on it.

staudenmeir commented 2 years ago

I released v1.15.3 with hasManyDeepFromRelationsWithConstraints():

return $this->hasManyDeepFromRelationsWithConstraints(
    [$this, 'records'],
    [new Record(), 'data']
);