Skip to content

Commit

Permalink
Scope TableRegistry finds to the current model alias
Browse files Browse the repository at this point in the history
It is otherwise possible to have overlapping translated records
  • Loading branch information
josegonzalez committed Nov 2, 2014
1 parent c0eb74d commit a802198
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Model/Behavior/TranslateBehavior.php
Expand Up @@ -183,10 +183,11 @@ public function beforeSave(Event $event, Entity $entity, ArrayObject $options) {
$fields = array_keys($values);
$primaryKey = (array)$this->_table->primaryKey();
$key = $entity->get(current($primaryKey));
$model = $this->_table->alias();

$preexistent = TableRegistry::get($table)->find()
->select(['id', 'field'])
->where(['field IN' => $fields, 'locale' => $locale, 'foreign_key' => $key])
->where(['field IN' => $fields, 'locale' => $locale, 'foreign_key' => $key, 'model' => $model])
->bufferResults(false)
->indexBy('field');

Expand All @@ -197,7 +198,6 @@ public function beforeSave(Event $event, Entity $entity, ArrayObject $options) {
}

$new = array_diff_key($values, $modified);
$model = $this->_table->alias();
foreach ($new as $field => $content) {
$new[$field] = new Entity(compact('locale', 'field', 'content', 'model'), [
'useSetters' => false,
Expand Down

0 comments on commit a802198

Please sign in to comment.