Model For Mysql Auto Revision

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?

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



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?? ::)

what’s wrong using 2 tables - say master and history?

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?

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.