Doctrine 2 - Retrieving the lastest record from history table

256
January 13, 2017, at 09:19 AM

Using a status_history table that will save the date and time a status was modified for a particular record in entries, I'm trying to find the easiest way to also get the current status, AKA, the status with the lastest date.

For instance consider the following: status_history

+----+----------+------------+-----------+
| id | entry_id |   status   | timestamp |
+----+----------+------------+-----------+
|  1 |        1 | Processing | 15:05:09  |
|  2 |        1 | In Review  | 15:05:18  |
|  3 |        1 | Complete   | 15:05:26  |
+----+----------+------------+-----------+

And of course, our entry: entries

+----+--------+
| id | title  |
+----+--------+
|  1 | Foobar |
+----+--------+

How can I retrieve, with DQL, the the latest status (technically the current status) for a particular entry, without having to maintain a latest_status_id column in my Entry entity?

Consider the call $entry->getCurrentStatus() would return "Complete". However, in the case we have a great amount of status records for that entry, a second query to load all statuses might turn into a performance drop.

NOTE: In this article they describe it with the extra column approach, using a locking mechanism for concurrency. I'd like to avoid this approach unless this is the correct one, since we're trying not to have double relations for each table (status_history.entry_id and entry.latest_history_id).

Rent Charter Buses Company
READ ALSO
php Password verify for override feature returns false

php Password verify for override feature returns false

I am trying to create an override feature where users type in existing login credentials, verify that a result row is returned matching those credentials, and then verifying that the user has the override role assigned to themIf both MySQL statements...

327
Conditional ordering based on field contents

Conditional ordering based on field contents

I have an SQL table that contains

370
logger.debug; outputting NULL respsonse

logger.debug; outputting NULL respsonse

So Im having trouble finding out why Im getting NULL for my loggerdebug response for this code

351
Will a multi-coulmn Index (name,type) be useful for where clause with in operator

Will a multi-coulmn Index (name,type) be useful for where clause with in operator

I have a table where i have a multi column index (name, type)Will the index be helpful for a query like

309