-
Notifications
You must be signed in to change notification settings - Fork 352
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
Fix container resolution and morph map for extended models #1933
base: 1.x
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
update method override add namespace
a82f217
to
edb019f
Compare
This change edb019f was the missing piece to get green in our projects. |
update namespace
update condition
I know this PR is huge, but here is the gist. I basically went through the whole codebase and did just a few things:
I also tested that everything works in https://github.com/dystcz/lunar-api, where I extend almost every Lunar model and it works great. |
@theimerj Looks like there was some overlap with a PR, are you able to take a look at the conflicts? |
Hey @alecritson, I will get to it soon. Thank you @wychoong for pointing these things out. |
add custom product model for testing model extending
Thanks for this PR, I've had a little look and we've discussed it internally briefly, one point we raised was the introduction of Language::modelClass()::getDefault(); I think this feels a bit off and not something we'd really want throughout the codebase as it doesn't really feel like a natural use of Eloquent and is a bit of a maintenance overhead we'd rather not introduce. Was the main purpose of this so that you are always interacting with the extended model? Since I don't think the panel code should be concerned with this and using the Lunar models should just work as well. There might have been an issue with resolving the correct model by Lunar but hopefully this should be resolved in #1949 as there was a bug with this. Additionally I think that same PR should resolve the issue with the shipping breakdown hydration 🤔 |
The solution introduced in this PR seems tedious at first, which it is (I went through the process), but if you comply with the correct way of resolving implementations out of the container in the future as well, the problems introduced are basically mitigated for good. Lastly I find the introduction of tests which cover the functionality with extended models in mind is quite important in order to globally catch possible bugs which may arise in the future. Bottom line: I tested the #1949 briefly locally and it really seems to have resolved the discovered issues. However, the test coverage is not ideal and I personally believe that the whole codebase should rely on automatic dependency injection more (at the very least in all the method calls where you can type hint the interfaces instead of concrete implementations). This alone mitigates a lot of problems. Let me know how to proceed. We can scratch this PR all together. We can keep some of the changes and scrach the rest you don't like. Your call. Please let me know and I will act accordingly. Thank you. |
I think you're correct in the sense that Lunar should be able to resolve the concrete class, but the underlying core code does not need to resolve to those classes, Lunar should should still be able to use it's own models. The point of model extending is to allow developers to bring their own model classes, which extend the Lunar ones, to add functionality on top of Lunar. But also for Lunar itself to not be concerned about that and still use the base models under the hood. For example if the developer adds their own model method, the Lunar core is never going to try and call that method so it doesn't really need to know about it. I think if we wanted to go down the path of Lunar using the concrete class then really we should use dependency injection.
We are currently not concerned about more than one level of inheritance and would consider it unsupported.
Yeah I understand what you're saying here and I updated the PR to use the
In short I think the best things to take away from the PR are:
The only thing we wouldn't include is the |
Hello @alecritson, thank you for your reply.
Understood. Your approach actually made me refactor Lunar API models, because creating deeply nested inheritance is not a way to go.
Ok, if only one level of inheritance will be supported by Lunar it should probably be written in the docs and a check could be introduced in the model manifest. I can prepare something.
Great to hear. That should minimize the performance issue I guess.
Ok, I will merge conflicts and rework the PR removing Thanks again. Have a great day. |
This PR aims to fix #1930 as proposed here: #1932
Problem:
The problem appears to be double serialization of certain casted attributes, specifically
$shippingBreakdown
and$taxBreakdown
, because at first the model isCart
, but when it goes through pipelines, it is resolved asCustomCart
and this namespace corrupts attribute serialization, so when it tries to set eg.$order->shipping_breakdown
, it tries to set a json encoded value instead of theShippingBreakdown
class.Specifically this part of
ShippingBreakdown
/TaxBreakdown
gets called when it should not.Possible solution:
Resolve correct models in pipelines: