So, I have a table of statuses
. On this table of statuses I have a foreign_key
representing the workflow that the status belongs to.
Now my question is, looping through the list of statuses will put them in order of Id, but say I insert a new status and want it to be in certain location in the list not just added to the bottom how would i do that?
Do I need to add an extra field that I could use to manipualte the order in which the statuses are printed out?
This question is different from the one that it may be a copy of because, I am simply asking how to order array of objects if there is no unique identifier for order other than ID or an Index. I'm not looking for alphabetical or reversed.
Say I have array of statuses coming from my database like so
[
{id: 1, status: 'receive'},
{id: 2, status: 'scan'},
{id: 3, status: 'prepare'},
{id: 4, status: 'review'},
{id: 5, status: 'complete'},
]
And then I want to insert a new object however I want it to be 4th in the list but of course when I create the new status it will just use the next ID available... so the array would like this
[
{id: 1, status: 'receive'},
{id: 2, status: 'scan'},
{id: 3, status: 'prepare'},
{id: 4, status: 'review'},
{id: 5, status: 'complete'},
{id: 6, status: 'file'},// this being the new status created
]
So now when I return an array of all statuses how could I actually place the status 4th in list with the given properties available like so
[
{id: 1, status: 'receive'},
{id: 2, status: 'scan'},
{id: 3, status: 'prepare'},
{id: 6, status: 'file'},// this being the new order of statuses
{id: 4, status: 'review'},
{id: 5, status: 'complete'},
]