laravel-merged-relations: Incompatible with staudenmeir/eloquent-has-many-deep?
Hello, I am already using staudenmeir/eloquent-has-many-deep relationships and wanted to use this package as well. However, I noticed these seem to be incompatible, am I correct?
staudenmeir/laravel-merged-relations: v1.5.2 staudenmeir/eloquent-has-many-deep: v1.17.1 Laravel: 9.46
When I’m trying to create a merged view with a relation which is defined using hasManyDeepFromRelations(), it uses the wrong ‘base model’
In model “A”:
public function c()
{
return $this->hasManyDeepFromRelations($this->b(), (new B)->c());
}
Creating schema:
Schema::createMergeViewWithoutDuplicates(
'all_cs',
[(new A)->c()]
);
Results in:
CREATE OR REPLACE
ALGORITHM = UNDEFINED VIEW `all_cs` AS
select
`cs`.`id` AS `id`,
`cs`.`name` AS `name`,
`cs`.`created_at` AS `created_at`,
`cs`.`updated_at` AS `updated_at`,
`bs`.`id` AS `laravel_foreign_key`,
'App\\Models\\C' AS `laravel_model`,
'' AS `laravel_placeholders`,
'' AS `laravel_with`
from
...
Expected result:
I was expecting it would do
`as`.`id` AS `laravel_foreign_key`
instead of
`bs`.`id` AS `laravel_foreign_key`
It does create the correct query to query using a B model. It seems to skip the first level (from what I would expect, at least).
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (7 by maintainers)
I pushed a test fix into the
has-many-deep-fixbranch. Replace the package’s version constraint in yourcomposer.jsonwithdev-has-many-deep-fixand runcomposer update staudenmeir/laravel-merged-relations.@staudenmeir that is working.
Thank you @staudenmeir!
@Naoray Yeah, that’s the same issue. Thanks for the offer, but I’m almost finished with the fix. I’ll provide you with a branch to test it. What Laravel version are you using?
I’m still working on the fix.
I know what the issue is, I’m working on a fix.