Is there a way to target all tables in order to get the (x) last modified element(s) of each table and order them by date (last modified) ?
There is no exact way in order to achieve this but you can do it programmatically.
Create a table with fields like this: id, modelname, modification_date
and fill it with the selected elements from the other tables (with SELECT INTO, or do it with php insert).
Then make a select with ORDER BY modification_date DESC.
After you can iterate over on the result, and get each item with a get on the proper model (from modelname field). You can append each item to a result array what you can return then.
Thank you for taking time to answer.
In fact, there are several ways to achieve this.
But I was wondering if there was a “cake” way.
I think (I did not try) I could use mysql command, something like :
->execute(SELECT table1.modified, table2.modified FROM table1, table2 WHERE table1.modified = “some_date”, table2.modified = “some_date”);
Any other idea ? or betterment ?
The idea in my last post is probably good but I cannot make it work (in fact, I’m not a mysql pro
At last, I wrote a latest() method in each table converted the query to array and used Hash::merge and ordered it by “modified”.
It works fine and is decently fast enough.