-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Static relations #17
Comments
This issue is to collect different point of views so please provide yours! |
|
_ 2. Would become more explicit when we get resolvable properties in core. Some other thing we lose with my proposal is things like forcing joins in a relation, not sure if that is something people do? |
Do you mean
Nothing I can think of immediately. |
I'll try to work on a simple PoC |
@samdark could you move this to |
+1 for this idea In issues i see feature requests for some features from eloquent like sync junction relations or polymorphic relations support, and as the fact - in eloquent relation definitions store more information https://github.com/illuminate/database/tree/master/Eloquent/Relations |
Currently relationship definitions in AR are defined as non static getters. In reality an AR class represents a table and an instance of that class represents a record.
Relations are defined at the table level, but because AR uses non-static getters our query classes need to instantiate a dummy model for greedy queries.
Requirements for AR relationships:
Pros of current approach:
Cons:
In Yii1 we had a single function defining the relationships but we also had the dummy model due to lack of late static binding. This allowed for enumeration but had other down sides.
What if, in Yii3 we try to get the best of both? Suppose we define relationships as static functions:
Internally we would have a sound definition of the relationship, from this we can:
From a consumer point of view nothing changes:
getCustomers
via__invoke()
->customers
via__get()
Pros:
Cons:
The text was updated successfully, but these errors were encountered: