Skip to content

Commit

Permalink
Fix #2721 in TranslateBehavior::beforeFind() supporting both Model::f…
Browse files Browse the repository at this point in the history
…ield('fieldname') and Model::read('fieldname')
  • Loading branch information
joostdekeijzer committed Jan 29, 2014
1 parent 9b4c2f3 commit 987187e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -139,6 +139,8 @@ public function beforeFind(Model $Model, $query) {
}
unset($this->_joinTable, $this->_runtimeModel);
return $query;
} elseif (is_string($query['fields'])) {
$query['fields'] = String::tokenize($query['fields']);
}

$fields = array_merge(
Expand Down
26 changes: 26 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -232,6 +232,32 @@ public function testLocaleSingle() {
)
);
$this->assertEquals($expected, $result);

$result = $TestModel->field('title', array('TranslatedItem.id' => 1));
$expected = 'Title #1';
$this->assertEquals($expected, $result);

$result = $TestModel->read('title', 1);
$expected = array(
'TranslatedItem' => array(
'id' => 1,
'slug' => 'first_translated',
'locale' => 'eng',
'title' => 'Title #1',
'translated_article_id' => 1,
)
);
$this->assertEquals($expected, $result);

$result = $TestModel->read('id, title', 1);
$expected = array(
'TranslatedItem' => array(
'id' => 1,
'locale' => 'eng',
'title' => 'Title #1',
)
);
$this->assertEquals($expected, $result);
}

/**
Expand Down

0 comments on commit 987187e

Please sign in to comment.