Hi all,
I need to configure a DataList with a bunch of child records, including some of the fields of it's many-to-one parent relation. If possible, I'd prefer to include that parent data using a left join in one sweep, instead of using multiple queries to fetch a parent for each child.
I've tried to change the query/DataQuery of an existing DataList (created by a SearchContext elsewhere) to include a parent field.
So far, I've:
$dataList = $dataList->alterDataQuery(
function($dataQuery) {
$dataQuery->applyRelation('Parent');
$dataQuery->setQueriedColumns(['ID', 'OtherChildField', 'Parent.Name']);
echo $dataQuery->sql();
}
);
The applyRelation method perfectly adds a left join, and I even can use where statements based on fields of the parent.
But what do I miss to include the Parent.Name field in the SELECT clause?
Having traced through the code, it seems like the dataQuery (or it's query) doesn't allow me to include fields other that the model's (child) own fields...
Even though the DataList->getFinalisedQuery has a parameter to pass custom fields, the DataList->sql() method doesn't provide this parameter, and the getFinalisedQuery gets to decide which fields are allowed, disregarding all fields that don't belong in the DataList's model.
I'd appreciate any Idea's :)
Ronald