MrJ
(Ccd384321wpqw)
1
Hii, I’m still new to Yii.
I have a table mydata
that I want to keep a revision history for in table _mydata
using MySQL. It works great, no problems!
See this post: hirmet.com/mysql-versioning-records-of-tables-using-triggers
The problem is when I try to make a single model for this in Yii, I can only point to 1 table. The model should point to:
-
_mydata
for "SELECT" type statements (read)
-
mydata
for "INSERT", "UPDATE", and "DELETE" statements (write)
How do I set this up in a single model file?
MrJ
(Ccd384321wpqw)
2
Helpful hint:
This is how I select only the most recent records from the revision table _mydata
SELECT t1 . *
FROM _mydata AS t1
LEFT OUTER JOIN _mydata AS t2 ON ( t1.id = t2.id
AND (
t1.version < t2.version
) )
WHERE t1.version IS NULL
MrJ
(Ccd384321wpqw)
3
Really?? Nobody has run into this before?
This seems like the best way to do this in MySQL, but maybe there is a better way.
I’m open to suggestions?? 
rootbear
(Alex Xm)
4
what’s wrong using 2 tables - say master and history?
MrJ
(Ccd384321wpqw)
5
Thanks for the reply.
Good idea. I am using 2 tables, but I am trying to combine it into 1 model in yii. Do you know how to do that?
rootbear
(Alex Xm)
6
i guess you need HAS_MANY relation from master to history;
BELONG_TO from history to master.
everytime you got new version, you push the old one into history.