Skip to content

Draft: Add back database code in Registration Entity class

This is a return to a more straight forward approach where we treat the Entity classes as Database models. It is a continuation of the work in !2176, but eliminates the Data models by incorporating the code directly in the Entity.

There's absolutely room for further work and refactoring opportunities here, especially when we do the same for other entities. However, I thought it would be worthwhile to present it a this stage to get some feedback on the direction.

In addition to the Registration Entity class itself, I have tried to update the related parts of include/accounts.php so it can be seen how it affects the code using the entities.

Things worth noting:

  • The properties of the object constructed is public readonly. This eliminates the need for 'getter' methods. We can access the properties directly from client code. However, it also means we can not change the values of the properties after the object is constructed. This may not be as much of a problem as it may seem, but it may be a thing to consider going forward.
  • Due to the above, there's really no need for setter methods either. If we want to change an object, we need to construct a new one. I'm thinking that one or more update methods that update the database and then fetch the updated record as a new object is a usable pattern here. That's one of the things we're missing by not having the intermediate Data model class, which could handle this transparently for the client code.
  • The static by_query method can potentially be parameterized further, so that it could be moved to a base class instead of being repeated in each entity class. This needs a bit further exploration to find the most elegant form.

Merge request reports

Loading