views:

217

answers:

2

There's a way to get which fields were modified after a update query?

I want to keep track what field XXX user modified... any ways using active records?

A: 

solution

instructions:

  1. SELECT row, that user wants to modify
  2. UPDATE it
  3. Compute differences between selected and update it
  4. Store the differences somewhere (or mail it, show it, whatever)

simple

Adam Kiss
But its a "edit page" using the original "add" form... so all fields are sent (via POST) by the view!
Roberto
yes... and? when updating database in your module (or controller), you have new values at least in post array - with some id also. So first select by id, save to array. then update. and then just compare arrays - the one from `$_POST` and the second from `SELECT` - are we misunderstanding each other?
Adam Kiss
i guess i got the ideia now.... Thank you very much ;)
Roberto
A: 

There is no way using active record to get this easily, but if you are only supporting one specific database type (let's say MySQL) you could always use Triggers?

Or, Adam is about right. If you have a WHERE criteria for your UPDATE you can SELECT it before you do the UPDATE then loop through the old and new versions comparing.

This is exactly the sort of work Triggers were created for, but of course that puts too much reliance on the DB which makes this less portable yada yada yada.

Phil Sturgeon