When you say “classes all the way down,” it reminds me of how I’ve built some of my apps, for example, one that manages trucks, versions, crates, and so on, all structured through nested classes. That makes me wonder: is using Model
classes really worth the effort here?
Maybe I’m missing something in your question, or I don’t fully grasp the benefits of Model
classes. But if I understand both correctly, I think sticking with good old manual serialize/deserialize might be the better route.
I haven’t used Model
classes myself (I haven’t created any new apps since they were introduced), but my impression is they handle a lot of functionality out of the box. My concern is that, as your use case drifts away from what’s included in those built-in features, you may find yourself putting in more effort just to keep using them, when the traditional approach would be simpler and faster.
I use simple object columns for all data that doesn’t need to be searchable. Every table has a few searchable fields and one or two simple object columns holding the main data. For instance, a simplified Trucks
table might have three columns: two searchable ones, project_number
and truck_number
, and one simple object column, versions
. That column contains a list of versions, each a dictionary with the full version content. When users make changes and save, a new version gets appended. This way I can track who changed what and when, for any truck. I’ve seen trucks with 0.5MB of data in that versions
column.
My Truck
class manages a list of Version
instances, each Version
handles its metadata and content, the content holds lists of Crate
instances, each Crate
contains lists of Panel
or Misc
instances. Classes all the way down.
Each class knows how to serialize and deserialize itself into and from a simple object. It gets more involved in some cases, for example, if crate number X is unchanged between two versions, instead of repeating it, the system stores a reference to the crate in the earlier version. So the serializer/deserializer takes care of compressing and expanding the data as needed.
I really don’t see how Model
classes would help in a scenario like this.
Where, in this example, would a Model
class make things easier?