From b1510083714ca185619f322941dc1fb637b0c905 Mon Sep 17 00:00:00 2001 From: AD7six Date: Sun, 1 Mar 2015 21:52:40 +0000 Subject: [PATCH] Rename model to referenceName While 'model' is the field name, as a config key it is quite meaningless without looking how it's used. Changed to reference name as, while not perfect, it's more descriptive than "model". --- src/ORM/Behavior/TranslateBehavior.php | 10 +++++----- tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ORM/Behavior/TranslateBehavior.php b/src/ORM/Behavior/TranslateBehavior.php index 78a18e485e5..9950d04cb7e 100644 --- a/src/ORM/Behavior/TranslateBehavior.php +++ b/src/ORM/Behavior/TranslateBehavior.php @@ -74,7 +74,7 @@ class TranslateBehavior extends Behavior 'fields' => [], 'translationTable' => 'I18n', 'defaultLocale' => '', - 'model' => '', + 'referenceName' => '', 'allowEmptyTranslations' => true, 'onlyTranslated' => false, 'strategy' => 'subquery' @@ -90,7 +90,7 @@ public function __construct(Table $table, array $config = []) { $config += [ 'defaultLocale' => I18n::defaultLocale(), - 'model' => $table->alias() + 'referenceName' => $table->alias() ]; parent::__construct($table, $config); } @@ -108,7 +108,7 @@ public function initialize(array $config) $this->setupFieldAssociations( $this->_config['fields'], $this->_config['translationTable'], - $this->_config['model'], + $this->_config['referenceName'], $this->_config['strategy'] ); } @@ -268,7 +268,7 @@ 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->_config['model']; + $model = $this->_config['referenceName']; $preexistent = $this->_translationTable->find() ->select(['id', 'field']) @@ -480,7 +480,7 @@ protected function _bundleTranslatedFields($entity) $contents[$i]->set('id', $results[$i], ['setter' => false]); $contents[$i]->isNew(false); } else { - $translation['model'] = $this->_config['model']; + $translation['model'] = $this->_config['referenceName']; $contents[$i]->set($translation, ['setter' => false, 'guard' => false]); $contents[$i]->isNew(true); } diff --git a/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php b/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php index c26bcdefe7d..4fe7724589c 100644 --- a/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php +++ b/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php @@ -899,7 +899,10 @@ public function testChangingModelFieldValue() $table = TableRegistry::get('Articles'); $table->hasMany('OtherComments', ['className' => 'Comments']); - $table->OtherComments->addBehavior('Translate', ['fields' => ['comment'], 'model' => 'Comments']); + $table->OtherComments->addBehavior( + 'Translate', + ['fields' => ['comment'], 'referenceName' => 'Comments'] + ); $items = $table->OtherComments->associations(); $association = $items->getByProperty('comment_translation');