Strict Model: Dot-notation reference by search #211

Closed
opened 2020-11-20 04:20:26 +00:00 by jamie · 3 comments
jamie commented 2020-11-20 04:20:26 +00:00 (Migrated from git.hazaar.io)

Currently, we can use Hazaar\Model\Strict::get($key) with a $key specified in dot-notation to dive down into child objects to get data. However, if the child object key is not known, we would normally use Hazaar\Model\Strict::find((array)$criteria) to search for it. At the moment we can't do that with dot-notation so we can only use dot-notation to reference things with known keys.

What I would like to do, is extend the dot-notation syntax to allow for searching inside objects.

For example, I have a product type object which has an element named productNames, which is a child array object that contains objects of type ProductName. Traditionally, if we wanted to get the first product name, we could use dot-notation such as product.productNames.0.label to get the label field from the product name. Now say these names are not ordered, and we don't want the first one, we actually want one which has an element named productNameType which is a number indicating the type, and we want to find the one with type=3.

I would like to be able to use this syntax: product.productNames(productNameType=3).label to get the correct field.

This should be a relativly simple update as all the functionality is there, we just need to decode the dot-notation syntax and call find() internally when needed.

Currently, we can use `Hazaar\Model\Strict::get($key)` with a `$key` specified in dot-notation to dive down into child objects to get data. However, if the child object key is not known, we would normally use `Hazaar\Model\Strict::find((array)$criteria)` to search for it. At the moment we can't do that with dot-notation so we can only use dot-notation to reference things with known keys. What I would like to do, is extend the dot-notation syntax to allow for searching inside objects. For example, I have a `product` type object which has an element named `productNames`, which is a child array object that contains objects of type `ProductName`. Traditionally, if we wanted to get the first product name, we could use dot-notation such as `product.productNames.0.label` to get the label field from the product name. Now say these names are not ordered, and we don't want the first one, we actually want one which has an element named `productNameType` which is a number indicating the type, and we want to find the one with type=3. I would like to be able to use this syntax: `product.productNames(productNameType=3).label` to get the correct field. This should be a relativly simple update as all the functionality is there, we just need to decode the dot-notation syntax and call `find()` internally when needed.
jamie commented 2020-11-20 04:20:29 +00:00 (Migrated from git.hazaar.io)

created merge request !106 to address this issue

created merge request !106 to address this issue
jamie commented 2020-11-20 04:20:29 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !106

mentioned in merge request !106
jamie commented 2020-11-20 04:38:02 +00:00 (Migrated from git.hazaar.io)

mentioned in commit f97fa64203ca46fc5ac6b8f04010fec24d14dcce

mentioned in commit f97fa64203ca46fc5ac6b8f04010fec24d14dcce
jamie (Migrated from git.hazaar.io) closed this issue 2020-11-20 04:38:02 +00:00
jamie self-assigned this 2025-09-04 01:15:28 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#211
No description provided.