Hello!
I had a problem which is as follows:
using the $pages->find($selectors) method; I can get an array of pages in the system.
Is there any way to get an array of fields instead of an array of pages?
for example as in SQL query using not SELECT * FROM table WHERE fieldname=value;
And I need to get an array of one field as here: SELECT some_field FROM table WHERE another_field=value;?
Let me explain:
There is an array of pages with the template "Car" where there are fields of type Manufacturer, Model, etc. which are of type Page Reference.
Suppose I found all Cars with certain parameters
$selectors = "parent=$parent,template=page_car,dealer={$dealer_id}";
$cars = $pages->findMany($selectors);
And if I need to find all the manufacturers that can be in $cars
I do it in the following way:
$manufacturerParent = wire("pages")->get($manufacturerParentID);
$manufacturerList = wire("pages")->findMany("parent={$manufacturerParent}");
foreach($manufacturerList as $manufacturerItem) {
// I'm get all cars with selectors and with this manufacturer.
$carsInManifacturerCount = wire("pages")->count($selectors.",manufacturer=$manufacturerItem");
// if I have cars with this manufacturer I'm do something
if($carsInManifacturerCount > 0 ){
$resultManifacturerList = new StdClass();
$resultManifacturerList->id = $manufacturerItem->id;
$resultManifacturerList->title = $manufacturerItem->title;
$resultManifacturerList->count = $carsInManifacturerCount;
$marksListArray[] = $resultMarkList;
}
}
So here's my question, is there a more correct way to get all the Manufacturer without brute force in the same way as the SQL query given?
Thanks!