Thank you, Zaky, for your ideas. I have to say, I was thinking pretty much the same way before I read you post--Using beforeSave to create an sql statement which would be stored in an undo table which would get the data back to the way it was. The way you laid it out is very clever, and it may be the way to go, but as you say, it will take some more thought.
I'm new to cake, but it seems like it would make quite a mess to try to create sql statements which would undo any save. It almost defeats the purpose of letting cake do the sql for me. What if the undo table looked like this: table_name action (update, delete, or insert) fields (could contain the data for each field delimited by comma [would be null if action is delete]) table_id (if action is update or delete) undo_num (so that multiple entries in this table could be linked as one action) does that seem like it would cover it? That way, you wouldn't have to write any sql, you could just construct the data... Thoughts? On Apr 25, 3:20 am, Zaky Katalan-Ezra <procsh...@gmail.com> wrote: > About the auto increment I meant the mysql column property AI. > > About undo: > In that case if you don't save your sessions to table and the session is > lost it's impossible to undo. > > Usually undo implemented with the state pattern. > > But in your case , I'll recommend keeping the initial data locally or to > undo table that will hold update statements. > > 1. undo table: > table_name > row_id > update_statement > > 2.Before editing a table1 create an update statement for each row and insert > it to the update table. > insert into undo ('table1',1,'update table table1 set col1= 'old_val', .... > where id = 1' ); > > 3.update the table1 > 4. undo > a) select id from table 1 where id not in (select row_id from undo where > table_name = 'table1' ) > delete all the rows you get, these are all new rows. > b) run all update statements from undo table > If you get an error change the update statement to insert > statement, the user probably delete this row. > 5. delete from undo where table_name = 'table1'; > > If you add user id to this process each user will be able to undo only his > changes. > > I think its better to implement it with before update, after insert and > before delete mysql triggers. > This way you save only changed rows. > > Its just a sketch so don't take it as it is, think it over > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with > their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en