Skip to content

The order in which selector is written when using 'owner' selector changes the results #2075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jlahijani opened this issue May 19, 2025 · 0 comments

Comments

@jlahijani
Copy link

jlahijani commented May 19, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant