-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Handle magic calls on model and query builder correctly #325
Conversation
Too big to fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request is awesome. Congrats buddy! And thank you again for your work.
@nunomaduro Can we merge this and make a new |
@canvural Please do release v0.4.2 |
@nunomaduro Is there anything left to do here? Can we merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ok, so it's up to you. We can't merge because of the |
@nunomaduro Can we force merge this, since we're only waiting for the style ci? |
Done. |
@nunomaduro Do you have an ETA for the release? :D |
I was thinking maybe we can test it a little, with But I can make the release 0.4.3, if it's ok with @nunomaduro |
I will try the changes as soon as I am able (still today). Will report back in the issues once I got around to it. |
Thanks for the awesome work guys! |
@bobbybouwmann Share some love RT @canvural his work: https://twitter.com/can__vural/status/1186564559261388800. |
Ok. This turned out to be a little bigger PR than I imagined 😅 But the outcome is good! I tested it on my big project. And I could go to level 4 from level 3 without changing anything.
List of changes:
Model
class'__call
method is mimicked. If it's notincrement
ordecrement
calls are forwarded to\Illuminate\Database\Eloquent\Builder
\Illuminate\Database\Eloquent\Builder
__call
method is mimicked. With one exception. Local macros are not supported. Otherwise, all unknown calls are forwarded to\Illuminate\Database\Query\Builder
class. But return type is still\Illuminate\Database\Eloquent\Builder
get
on the query builder. This will returnCollection
class and elements of the collection correctly typehinted with the model.User::where('foo', 'bar')
was returning the model itself. See Wrong tests and possible wrong implementation #324 This is fixed nowfind
,firstOrCreate
etc.There might be an increased number of errors after these changes. But this is because there were false negatives before. For example Larastan would think
User:whereFoo('bar')->someRelation()
is a correct code and returning model instance. But that example is not a valid Laravel code in reality. So I guess any of this can't be considered as breaking change. And all the existing (which I didn't change) tests are passing, so existing functionality is preserved.I'm open to any comments and questions. About implementation or other things.