robwilkerson/CakePHP-Audit-Log-Plugin — Issue #1: json_object mismatch with related models in DELETE scenario
Author: joatcoder
Created: 2011-12-20 22:14:25+00:00
State: open

This may be a misunderstanding on my part, but thought I would bring it up here.

When DELETEing a model which has a related model also acting as Auditable, the related model's data overrides the _original field, so the saved json_object for the deletion contains the related model's data rather than the deleted model's.

I have a Member model with a hasOne relationship to MemberPreference. I added a log message to print the model->alias in beforeDelete, and when deleting a Member, I see the following:

2011-12-20 21:26:20 Debug:
AuditableBehavior::beforeDelete() - APP/plugins/audit_log/models/behaviors/auditable.php, line 83
ModelBehavior::dispatchMethod() - CORE/cake/libs/model/model_behavior.php, line 169
BehaviorCollection::trigger() - CORE/cake/libs/model/model_behavior.php, line 494
Model::delete() - CORE/cake/libs/model/model.php, line 1829
MembersController::delete() - /home/jack/devel/proto/trunk/cake_app/controllers/members_controller.php, line 2081
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 82
"beforeDelete: Member"
2011-12-20 21:26:20 Debug:
AuditableBehavior::beforeDelete() - APP/plugins/audit_log/models/behaviors/auditable.php, line 83
ModelBehavior::dispatchMethod() - CORE/cake/libs/model/model_behavior.php, line 169
BehaviorCollection::trigger() - CORE/cake/libs/model/model_behavior.php, line 494
Model::delete() - CORE/cake/libs/model/model.php, line 1829
Model::_deleteDependent() - CORE/cake/libs/model/model.php, line 1892
Model::delete() - CORE/cake/libs/model/model.php, line 1835
MembersController::delete() - /home/jack/devel/proto/trunk/cake_app/controllers/members_controller.php, line 2081
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 82
"beforeDelete: MemberPreference"

I am able to workaround by adding if ($this->_original != null) return true; to the start of the beforeDelete() method, at least in the one case that I see this happening.

Thanks for the great plugin!
Jack