Adding docs + exceptions for name translation.

Closes #2367
This commit is contained in:
mark_story 2011-12-30 20:39:04 -05:00
parent a4e3790196
commit b5f918765e
2 changed files with 21 additions and 1 deletions

View file

@ -368,7 +368,10 @@ class TranslateBehavior extends ModelBehavior {
/** /**
* Bind translation for fields, optionally with hasMany association for * Bind translation for fields, optionally with hasMany association for
* fake field * fake field.
*
* *Note* You should avoid binding translations that overlap existing model properties.
* This can cause un-expected and un-desirable behavior.
* *
* @param Model $model instance of model * @param Model $model instance of model
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3) * @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
@ -391,6 +394,11 @@ class TranslateBehavior extends ModelBehavior {
$field = $key; $field = $key;
$association = $value; $association = $value;
} }
if ($field === 'name') {
throw new CakeException(
__d('cake_dev', 'You cannot bind a translation named "name".')
);
}
if (array_key_exists($field, $this->settings[$model->alias])) { if (array_key_exists($field, $this->settings[$model->alias])) {
unset($this->settings[$model->alias][$field]); unset($this->settings[$model->alias][$field]);

View file

@ -868,4 +868,16 @@ class TranslateBehaviorTest extends CakeTestCase {
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* Test that an exception is raised when you try to over-write the name attribute.
*
* @expectedException CakeException
* @return void
*/
public function testExceptionOnNameTranslation() {
$this->loadFixtures('Translate', 'TranslatedItem');
$TestModel = new TranslatedItem();
$TestModel->bindTranslation(array('name' => 'name'));
}
} }