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.
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.
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.
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.
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.
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.