Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should afterUpdate method be triggered when saving object does not result in MySQL query? #1

Closed
gajus opened this issue Apr 26, 2014 · 3 comments
Labels

Comments

@gajus
Copy link
Owner

gajus commented Apr 26, 2014

Suppose that you construct an object, e.g.

<?php
$string = new \Sandbox\Model\String($this->db);
$string['name'] = 'foo';
$string->save(); // INSERTs object to the database and triggers "afterInsert" method
$string['name'] = 'bar';
$string->save(); // UPDATEs object's instance in the database and triggers "afterUpdate" method
$string->save(); // Does not not execute MySQL query because object state has not changed.

Should the 3rd call to save:

  1. Issue MySQL query? (even though it is assumed that it will not affect the record)
  2. If query is not executed, should the afterUpdate method be triggered?
@gajus gajus added the question label Apr 26, 2014
@gajus
Copy link
Owner Author

gajus commented Apr 26, 2014

The current implementation will not execute MySQL statement but will trigger the afterUpdate method.

@gajus gajus closed this as completed Apr 26, 2014
@qris
Copy link

qris commented May 5, 2014

Triggers may be defined on UPDATE that have side effects in the database, and the application may rely on those. Also, the timestamp of a record in the database would be updated by an UPDATE statement even if no values were changed.

Since MySQL does not allow an UPDATE statement with no SET clauses (i.e. it requires at least one column to be modified) you'd have to set a column to itself (e.g. ID = ID) which is odd. But I can't see any way to execute such a statement with MOA in application code, so there should be a way to force MOA to perform a null update.

@gajus
Copy link
Owner Author

gajus commented May 5, 2014

Well, that's the thing. I also thought that timestamp would be updated even if no values change. But a quick test will show you that this is not the case. Therefore, it left me in doubt a bit. Though, after implementing MOA in practise on several applications, I realised that "afterUpdate" trigger must go-off regardless of MySQL behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants