Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model::loadMissing() only accepts unique relation names #27039

Closed
phh opened this issue Jan 3, 2019 · 1 comment
Closed

Model::loadMissing() only accepts unique relation names #27039

phh opened this issue Jan 3, 2019 · 1 comment
Labels

Comments

@phh
Copy link
Contributor

phh commented Jan 3, 2019

  • Laravel Version: 5.7.19
  • PHP Version: 7.2
  • Database Driver & Version: 10.3.10-MariaDB

Description:

When using Model::loadMissing() relations containing the same name will be ignored.

Steps To Reproduce:

Example code:

$sourceRecipe->loadMissing([
    'ingredients.unit',
    'ingredients.unit.unit',
    'ingredients.unit.unit.association',
]);

Result:
{"exception":"Illuminate\\Database\\Eloquent\\RelationNotFoundException","exception_message":"Call to undefined relationship [association] on model [App\\Models\\Ingredients\\Units\\Unit]."}

Seems like it has to do with the way loadMissing() is loading these by using the same array key and value by using array_combine to combine these.

$segments:

array:4 [
  0 => "ingredients"
  1 => "unit"
  2 => "unit"
  3 => "association"
]

$path:

array:3 [
  "ingredients" => "ingredients"
  "unit" => "unit"
  "association" => "association"
]

Using load() instead seems to work but I'm interested in keeping the same relationships while loading another relation.

@driesvints
Copy link
Member

Seems like @staudenmeir is on it. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants