Skip to content

Conversation

dpanta94
Copy link
Member

@dpanta94 dpanta94 commented Oct 3, 2025

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.

@dpanta94 dpanta94 self-assigned this Oct 3, 2025
* The relationship value.
*
* @var Model|list<Model>|null
* @var Model|Model[]|LazyModelInterface|LazyModelInterface[]|null
Copy link
Contributor

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.

Copy link
Member Author

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;
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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?

Base automatically changed from feature/improved-relationships to release/2.0.0 October 3, 2025 19:10
@dpanta94
Copy link
Member Author

dpanta94 commented Oct 7, 2025

Closing in favor of upcoming PR with more a powerful/flexible API serving this purpose.

@dpanta94 dpanta94 closed this Oct 7, 2025
@dpanta94 dpanta94 deleted the feat/support-post-models-and-lazy-loading branch October 7, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants