Skip to content

Commit

Permalink
Rename model to referenceName
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
AD7six committed Mar 1, 2015
1 parent 62cfe3c commit b151008
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -74,7 +74,7 @@ class TranslateBehavior extends Behavior
'fields' => [],
'translationTable' => 'I18n',
'defaultLocale' => '',
'model' => '',
'referenceName' => '',
'allowEmptyTranslations' => true,
'onlyTranslated' => false,
'strategy' => 'subquery'
Expand All @@ -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);
}
Expand All @@ -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']
);
}
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php
Expand Up @@ -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');
Expand Down

0 comments on commit b151008

Please sign in to comment.