Description
I have the following structure on my site:
- /orders/ (orders template)
- order-1 (order template)
- order-2 (order template)
- order-3 (order template)
- ...
order template has:
- fulfillment_orders repeater
repeater_fulfillment_orders template has:
- shipments repeater
repeater_shipments template has:
- payloads repeater
Another way to say the above would be like this:
/orders/
/order-1/
- fulfillment_orders (repeater)
- shipments (repeater)
- payloads (repeater)
Now let's say I want to get all of the payloads where the order is not a "test" with some other things. I would do this:
$selector = [
"template=repeater_payloads",
"check_access=0",
"status!=unpublished",
"sort=datetime",
"payload_event_type.name=outgoing",
"payload_type.name=shipped-order",
"datetime>=2025-05-01 00:00:00",
"datetime<=2025-05-15 23:59:59",
// 3 owners (ORDER LEVEL)
"payloads.owner.shipments.owner.fulfillment_orders.owner.parent=/orders/",
"payloads.owner.shipments.owner.fulfillment_orders.owner.template=order",
"payloads.owner.shipments.owner.fulfillment_orders.owner.status!=unpublished",
"payloads.owner.shipments.owner.fulfillment_orders.owner.test=0",
"payloads.owner.shipments.owner.fulfillment_orders.owner.provider=foo",
// 2 owners (FULFILLMENT_ORDERS LEVEL)
"payloads.owner.shipments.owner.template=repeater_fulfillment_orders",
"payloads.owner.shipments.owner.status!=unpublished",
"payloads.owner.shipments.owner.location=bar",
// 1 owner (SHIPMENTS LEVEL)
"payloads.owner.template=repeater_shipments",
"payloads.owner.status!=unpublished",
];
// debugger says this translates to 5 sql queries
echo $pages->count(implode(",", $selector));
The above selector gives the correct results.
However if I swapped the positions of "1 owner" and "3 owners" like this:
$selector = [
"template=repeater_payloads",
"check_access=0",
"status!=unpublished",
"sort=datetime",
"payload_event_type.name=outgoing",
"payload_type.name=shipped-order",
"datetime>=2025-05-01 00:00:00",
"datetime<=2025-05-15 23:59:59",
// 1 owner (SHIPMENTS LEVEL)
"payloads.owner.template=repeater_shipments",
"payloads.owner.status!=unpublished",
// 2 owners (FULFILLMENT_ORDERS LEVEL)
"payloads.owner.shipments.owner.template=repeater_fulfillment_orders",
"payloads.owner.shipments.owner.status!=unpublished",
"payloads.owner.shipments.owner.location=bar",
// 3 owners (ORDER LEVEL)
"payloads.owner.shipments.owner.fulfillment_orders.owner.parent=/orders/",
"payloads.owner.shipments.owner.fulfillment_orders.owner.template=order",
"payloads.owner.shipments.owner.fulfillment_orders.owner.status!=unpublished",
"payloads.owner.shipments.owner.fulfillment_orders.owner.test=0",
"payloads.owner.shipments.owner.fulfillment_orders.owner.provider=foo",
];
// debugger says this translates to 2 sql queries
echo $pages->count(implode(",", $selector));
... then I get a different result! Notice that the correct one uses 5 sql queries vs. the incorrect one uses 2 sql queries.
I don't use owner selectors often, but they are powerful and more efficient, and it's very nice being able to crawl the relationships between pages/repeaters using multiple owner selectors (eg: a.owner.b.owner.c.owner) like I described (something that's undocumented but very powerful).
However as mentioned, it seems the order in which you define the pieces of the selector matters. Is this a bug? If not, is there documentation stating how the order of the pieces of a selector are supposed to influence the resulting sql queries?
Note: Using PW 3.0.247