I have a table "delivery" with a "status" column (yes, I still think in 
tables, not sure if this is a cause for concern...). I need to refactor it 
to track status history rather than just the current status. I would want 
to be able to query this data later to present history to the user.

I thought of something like splitting into tables "delivery" and 
"delivery_statuses", with timestamps as the delivery goes from status to 
status e.g. new -> in_progress -> delivered etc.

Then I thought this seems like a common-enough pattern. Is there any 
sqlalchemy magic should I be aware of for this type of scenario? Are hybrid 
attributes relevant? e.g. I can see that I'll want to easily query a 
delivery for its (current) status, and that could get messy. I have skimmed 
the hybrid attributes docs, but at the moment they're a bit Greek / new to 
me. However I do note that they have a section on hybrid attributes with 
relationships 
<https://docs.sqlalchemy.org/en/13/orm/extensions/hybrid.html#working-with-relationships>
.

On IRC, I was also recommended to check out versioning 
<https://docs.sqlalchemy.org/en/13/orm/examples.html#versioning-objects>, 
which seems to be an example rather than an integral part of sqlalchemy, 
and I'm not finding it any simpler to parse those docs.

Or is this a job for association proxy, which I'd always assumed was for 
simplifying many-to-many relationships, not a one-to-many like this. (
(In fact, this becomes a one-to-one relationship, once I limit 
"delivery_statuses" to the latest row.)

I appreciate any insight into the "best" way to build such a structure in 
sqlalchemy, and I'm happy to clarify my requirements more, feel free to ask 
me if anything is unclear.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/1f3c39d7-a5ce-4854-bbf2-fbf2456b0ecb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to