-
Notifications
You must be signed in to change notification settings - Fork 2
Support Post Models and Lazy Loading #33
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
Support Post Models and Lazy Loading #33
Conversation
* The relationship value. | ||
* | ||
* @var Model|list<Model>|null | ||
* @var Model|Model[]|LazyModelInterface|LazyModelInterface[]|null |
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 union return type will be parsed by the client code using this library.
This means the developer will have to think what to do for each case.
This looks like a leaky abstraction to me: the fact that a model is lazy or not is an implementation detail that should not leak to the client code using the model.
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 is a really good point and i agree that the client code should not have to think "what Object should i use to set this relationship", but i can't think of a good enough solution so far...
* @return ?ModelPersistable | ||
*/ | ||
public static function find( $id ); | ||
public static function find( $id ): ?ModelPersistable; |
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.
I think this should keep returning a Model
. This interface extends it and persistable models should hide how they read and write to the database form the client code.
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.
Just to be clear, what you are suggesting would mean that a Persistable model may return a model which isn't Persistable and as a result, client code would be unable to change it and save it without further checks.
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.
When you say Model
, @lucatume, are you referring to the abstract class or the interface?
Closing in favor of upcoming PR with more a powerful/flexible API serving this purpose. |
Introduces a PostModel which can be used to enable relationships of Models and WP_Posts. This should be the most common relationship our models will encounter so it seems logical to support it.
Introduces a system to enable lazy loading of Models in relationships to provide possibilities for better memory management. For example, a model could be resolved only when needed rather than always.