Created
February 27, 2019 12:03
-
-
Save garethellis36/f436fb0610cc1adfec19d6e7388e4628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Step extends AppModel | |
{ | |
public $belongsTo = ["Translator"]; | |
} | |
$results = model(Step::class)->find("first", [ | |
"conditions" => [ | |
"Step.translator_id IS NOT NULL", | |
], | |
"contain" => [ | |
"Translator" => [ | |
"NativeLanguage" | |
], | |
], | |
"fields" => [ | |
"Translator.id", | |
], | |
"limit" => 1, | |
"order" => ["Step.id DESC"], | |
]); | |
/** | |
* 'Translator' is "double-nested" | |
* | |
* array( | |
* 'Translator' => array( | |
* 'id' => '15', | |
* 'Translator' => array( | |
* 'id' => '15', | |
* 'NativeLanguage' => array() | |
* ) | |
* ) | |
* ) | |
* | |
* Removing the "fields" array in the query removes the double-nesting | |
* Someone else has reported similar: https://stackoverflow.com/questions/33980312/nested-result-while-using-cakephp-containable | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment