Skip to content

Instantly share code, notes, and snippets.

@garethellis36
Created February 27, 2019 12:03
Show Gist options
  • Save garethellis36/f436fb0610cc1adfec19d6e7388e4628 to your computer and use it in GitHub Desktop.
Save garethellis36/f436fb0610cc1adfec19d6e7388e4628 to your computer and use it in GitHub Desktop.
<?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