diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 203bf9b55..07e2635f2 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -245,11 +245,26 @@ class TranslateBehavior extends ModelBehavior { * @return array The list of translated fields that are in the conditions. */ protected function _checkConditions(Model $Model, $query) { - $conditionFields = array(); if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions']))) { - return $conditionFields; + return array(); } - foreach ($query['conditions'] as $col => $val) { + return $this->_getConditionFields($Model, $query['conditions']); + } + + /** + * Extracts condition field names recursively. + * + * @param Model $Model The model being read. + * @param array $conditions The conditions array. + * @return array The list of condition fields. + */ + protected function _getConditionFields(Model $Model, $conditions) { + $conditionFields = array(); + foreach ($conditions as $col => $val) { + if (is_array($val)) { + $subConditionFields = $this->_getConditionFields($Model, $val); + $conditionFields = array_merge($conditionFields, $subConditionFields); + } foreach ($this->settings[$Model->alias] as $field => $assoc) { if (is_numeric($field)) { $field = $assoc; diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 37c42465b..5f74583c2 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -1460,7 +1460,7 @@ class TranslateBehaviorTest extends CakeTestCase { 'table' => (object)array( 'tablePrefix' => '', 'table' => 'article_i18n', - 'schemaName' => 'test', + 'schemaName' => 'cakephp_test', ), 'conditions' => array( 'TranslatedArticle.id' => (object)array( @@ -1478,7 +1478,7 @@ class TranslateBehaviorTest extends CakeTestCase { 'table' => (object)array( 'tablePrefix' => '', 'table' => 'article_i18n', - 'schemaName' => 'test', + 'schemaName' => 'cakephp_test', ), 'conditions' => array( 'TranslatedArticle.id' => (object)array( @@ -1535,13 +1535,30 @@ class TranslateBehaviorTest extends CakeTestCase { ), 'fields' => 'COUNT(DISTINCT(`TranslatedArticle`.`id`)) AS count', 'joins' => array( + array( + 'type' => 'INNER', + 'alias' => 'TranslateArticleModel', + 'table' => (object)array( + 'tablePrefix' => '', + 'table' => 'article_i18n', + 'schemaName' => 'cakephp_test', + ), + 'conditions' => array( + '`TranslatedArticle`.`id`' => (object)array( + 'type' => 'identifier', + 'value' => '`TranslateArticleModel`.`foreign_key`', + ), + '`TranslateArticleModel`.`model`' => 'TranslatedArticle', + '`TranslateArticleModel`.`locale`' => 'eng', + ), + ), array( 'type' => 'INNER', 'alias' => 'I18n__title', 'table' => (object)array( 'tablePrefix' => '', 'table' => 'article_i18n', - 'schemaName' => 'test', + 'schemaName' => 'cakephp_test', ), 'conditions' => array( 'TranslatedArticle.id' => (object)array( @@ -1553,24 +1570,6 @@ class TranslateBehaviorTest extends CakeTestCase { 'I18n__title.locale' => 'eng', ), ), - array( - 'type' => 'INNER', - 'alias' => 'I18n__body', - 'table' => (object)array( - 'tablePrefix' => '', - 'table' => 'article_i18n', - 'schemaName' => 'test', - ), - 'conditions' => array( - 'TranslatedArticle.id' => (object)array( - 'type' => 'identifier', - 'value' => 'I18n__body.foreign_key', - ), - 'I18n__body.model' => 'TranslatedArticle', - 'I18n__body.field' => 'body', - 'I18n__body.locale' => 'eng', - ), - ), ), 'limit' => 2, 'offset' => null, diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 8c7148d89..f2c1713b9 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -6505,6 +6505,23 @@ class ModelReadTest extends BaseModelTest { ), 'fields' => 'COUNT(DISTINCT(`TranslatedArticle`.`id`)) AS count', 'joins' => array( + array( + 'type' => 'INNER', + 'alias' => 'TranslateArticleModel', + 'table' => (object)array( + 'tablePrefix' => '', + 'table' => 'article_i18n', + 'schemaName' => 'cakephp_test', + ), + 'conditions' => array( + '`TranslatedArticle`.`id`' => (object)array( + 'type' => 'identifier', + 'value' => '`TranslateArticleModel`.`foreign_key`', + ), + '`TranslateArticleModel`.`model`' => 'TranslatedArticle', + '`TranslateArticleModel`.`locale`' => 'eng', + ), + ), array( 'type' => 'INNER', 'alias' => 'I18n__title', @@ -6523,24 +6540,6 @@ class ModelReadTest extends BaseModelTest { 'I18n__title.locale' => 'eng', ), ), - array( - 'type' => 'INNER', - 'alias' => 'I18n__body', - 'table' => (object)array( - 'tablePrefix' => '', - 'table' => 'article_i18n', - 'schemaName' => 'test', - ), - 'conditions' => array( - 'TranslatedArticle.id' => (object)array( - 'type' => 'identifier', - 'value' => 'I18n__body.foreign_key', - ), - 'I18n__body.model' => 'TranslatedArticle', - 'I18n__body.field' => 'body', - 'I18n__body.locale' => 'eng', - ), - ), ), 'limit' => 2, 'offset' => null, @@ -7325,7 +7324,7 @@ class ModelReadTest extends BaseModelTest { 'limit' => 2, ); $result = $TestModel->find('count', $options); - $this->assertEquals(2, $result); + $this->assertEquals(3, $result); } /**