-
Notifications
You must be signed in to change notification settings - Fork 88
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
Translate attributes / indexes not cleared when model is deleted #652
Comments
Correct me if I'm wrong, but could this be caused by 508c42c since it happens across two separate queries now. One idea is to use GC to clean up orphaned records. |
That's true, when implementing 508c42c I was not aware that translation tables contain orphaned records by design. But I think that a cleanup of related translated records in beforeDelete event should solve this issue? |
Yes, if you are happy with that, let's hook afterDelete inside
|
If anyone else is interested, I fixed this by extending the base model: $model->bindEvent('model.beforeDelete', function() use ($model) {
if($model->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) {
DB::table('rainlab_translate_attributes')
->where('model_id', $model->getKey())
->where('model_type', get_class($model))
->delete();
DB::table('rainlab_translate_indexes')
->where('model_id', $model->getKey())
->where('model_type', get_class($model))
->delete();
}
}); And I also added a console command to clean existing orphaned records. |
Translatable attributes/indexes are not removed from the database after a parent model is deleted, which can cause issues in some situations when using
transWhere
.This was already reported (#211), but I am reopening the issue, since it has not been resolved and it's causing our production apps to fail in unexpected ways
The text was updated successfully, but these errors were encountered: