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

withDefault does not seem to be called on morphTo relationships. #24055

Closed
vpratfr opened this issue Apr 30, 2018 · 2 comments
Closed

withDefault does not seem to be called on morphTo relationships. #24055

vpratfr opened this issue Apr 30, 2018 · 2 comments

Comments

@vpratfr
Copy link
Contributor

vpratfr commented Apr 30, 2018

  • Laravel Version: 5.6.18
  • PHP Version: 7.1

Description:

The method withDefault does not seem to be called on morphTo relationships.

Steps To Reproduce:

I have a table Mission which relates to other tables to store mission specific data, depending on the mission template. For example, when mission template is 'create-company', we use a CreateCompanyData model.

The Mission model has a mission_data() relationship described as:

public function mission_data() : MorphTo { 
    return $this->morphTo('mission_data')
                ->withDefault(function() {
                    if ($this->template==='') {
                        return new CreateCompanyData();
                    }
                    // Handle other template values + throw when template unknown
                    // ...
                });
}

When debugging my unit tests, it appears that breakpoints never get hit when placed inside the withDefault callback, even when no relation has been provided yet (function simply returns null, as if there was no withDefault call defined.

@vpratfr
Copy link
Contributor Author

vpratfr commented May 2, 2018

Thanks :)

@vpratfr
Copy link
Contributor Author

vpratfr commented Jul 2, 2018

@taylorotwell @staudenmeir Re-opened in #24725 after some field testing

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

No branches or pull requests

1 participant