I know this is a simple problem, I know I've done it a million times before, but I am just drawing blanks left and right this afternoon...
I have an entity, it progresses thru several states. I want to keep a history of these states, so I create a new entry in my status table for each state.
I'm coming across one problem because sometimes my states occur in such quick succession that the timestamps on the two rows are equal.
I'm also having a little trouble writing the queries to determine all of the entities in a current state.
The solution that comes to mind immediately is to add a "state closed" boolean field, but this seems sloppy to me. Is this a good solution, or perhaps I'm overlooking something obvious?
i.e.
Thanks,
Rob
I have an entity, it progresses thru several states. I want to keep a history of these states, so I create a new entry in my status table for each state.
I'm coming across one problem because sometimes my states occur in such quick succession that the timestamps on the two rows are equal.
I'm also having a little trouble writing the queries to determine all of the entities in a current state.
The solution that comes to mind immediately is to add a "state closed" boolean field, but this seems sloppy to me. Is this a good solution, or perhaps I'm overlooking something obvious?
i.e.
Code:
Table1
entity_id (fk)
status
timestamp
so now just to find out what status an entity is in I have to write
SELECT max(timestamp) FROM Table1 WHERE entity_id = X
then take that return, and run a
SELECT status FROM Table1 WHERE entity_id = X AND timestamp=(returned value)
but this is sometimes giving me two rows, so I need to fudge the results.
I dunno, the more I ramble the more a boolean stating whether or not the state is alive sounds good.... (especially when thinking of a "all entity_id's in state=Y", but I'd appreciate any desenting opinions.
Rob