I have looked through containable component and other questions here, but doesn’t look like that can help me.
Basically, I have paginate set to 1, which returns me something just like
Array
(
[0] => Array
(
[ModelName1] => Array
(
[id] => 83
[parent_id] => null
[field1] => value1
)
[AssociatedModelName1] => Array
(
[id] => 1
[field1] => value1
)
[children] => Array
(
[0] => Array
(
[ModelName] => Array
(
[id] => 42
[parent_id] => 83
[field1] => value1
[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 2
[field1] => value1
[field2] => value2
[field3] => value3
)
I am able to limit the output of ModelName1 and AssociatedModelName1 ‘s field by adding
$fields => array("ModelName1.field1")
to the setting array. In fact I pass this to the “column” of the DataTable Plugin’s component initialization, but it should be the same.
However, since there are SO MANY CHILDREN, and each children contains a lot of fields, I would like to get only the “field2” of each children.
How can I achieve that? If I specify “Children.ModelName1”, I get a SQL1054 error, which is column not found.
Any clue?
You must use a conditional array in one way or another: