From 987187ef8ce387ff460c9a06337ee2709897c97c Mon Sep 17 00:00:00 2001 From: joostdekeijzer Date: Wed, 29 Jan 2014 11:29:51 +0100 Subject: [PATCH] Fix #2721 in TranslateBehavior::beforeFind() supporting both Model::field('fieldname') and Model::read('fieldname') --- lib/Cake/Model/Behavior/TranslateBehavior.php | 2 ++ .../Model/Behavior/TranslateBehaviorTest.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 82800818a..154f52c59 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -139,6 +139,8 @@ class TranslateBehavior extends ModelBehavior { } unset($this->_joinTable, $this->_runtimeModel); return $query; + } elseif (is_string($query['fields'])) { + $query['fields'] = String::tokenize($query['fields']); } $fields = array_merge( diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 626376017..6c9fcdffb 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -232,6 +232,32 @@ class TranslateBehaviorTest extends CakeTestCase { ) ); $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); } /**