Query language tweak? From array element, is it $parent or $parent.parent

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Query language tweak? From array element, is it $parent or $parent.parent

bserdar
Here's some annoying quirk of the query language:

 We interpret association queries relative to the node they're defined. So, if an association field is defined as:

 ...
 some_assoc_field : { "type" ; 'reference",
                                    "entity": "X",
                                    "query": { "field":"_id", "op":"=", "rfield";"$parent.x_id" }
                                 }
...


The intend is to equate the _id of X to the x_id in the parent entity. The query fields are interpreted with respect to the node it is defined.

When we process this metadata, we replace that association field with an array. The array elements become object defined as the metadata of the associated entity. But, we treat arrays as two-level objects. So. the array "some_assoc_field" has children 0,1,2.... (the elements of the array), and then "some_assoc_field.0" has the fields of entity X. Because of this, the correct association query is:

   $parent.$parent.x_id

instead of

   $parent.x_id

If I interpret the fields wrt the array field itself (some_assoc_field), then

   $parent.x_id

would refer to the correct field, but the _id reference to X becomes:

    *._id

because array elements are the children of array field.

So, I can think of a couple of options:

 1) Keep it as is. $parent.$parent will be used to access parent entity fields
 2) Tweak array element interpretation so that $parent from an array element doesn't go to the array field, but to the parent of the array field. So, $parent.x_id will refer to the parent entity array field, and _id will refer to the X._id. The inconsistency here is that you refer to an array element field as:
    arrayField.*.someField
but from someField, if you have $parent.x, it refers to a field x at the same level as arrayField.

Let me know your preference. Is there a third option? Let me know that as well if you can think of one.
Reply | Threaded
Open this post in threaded view
|

Re: Query language tweak? From array element, is it $parent or $parent.parent

jewzaam
Administrator

Is this a problem with interpretation of $parent? Makes sense to have parent of array elements resolve to the parent of the array. I think we've had this discussion before. Sounds familiar at least.

On Sep 22, 2014 4:04 PM, "bserdar [via lightblue-dev]" <[hidden email]> wrote:
Here's some annoying quirk of the query language:

 We interpret association queries relative to the node they're defined. So, if an association field is defined as:

 ...
 some_assoc_field : { "type" ; 'reference",
                                    "entity": "X",
                                    "query": { "field":"_id", "op":"=", "rfield";"$parent.x_id" }
                                 }
...


The intend is to equate the _id of X to the x_id in the parent entity. The query fields are interpreted with respect to the node it is defined.

When we process this metadata, we replace that association field with an array. The array elements become object defined as the metadata of the associated entity. But, we treat arrays as two-level objects. So. the array "some_assoc_field" has children 0,1,2.... (the elements of the array), and then "some_assoc_field.0" has the fields of entity X. Because of this, the correct association query is:

   $parent.$parent.x_id

instead of

   $parent.x_id

If I interpret the fields wrt the array field itself (some_assoc_field), then

   $parent.x_id

would refer to the correct field, but the _id reference to X becomes:

    *._id

because array elements are the children of array field.

So, I can think of a couple of options:

 1) Keep it as is. $parent.$parent will be used to access parent entity fields
 2) Tweak array element interpretation so that $parent from an array element doesn't go to the array field, but to the parent of the array field. So, $parent.x_id will refer to the parent entity array field, and _id will refer to the X._id. The inconsistency here is that you refer to an array element field as:
    arrayField.*.someField
but from someField, if you have $parent.x, it refers to a field x at the same level as arrayField.

Let me know your preference. Is there a third option? Let me know that as well if you can think of one.


If you reply to this email, your message will be added to the discussion below:
http://dev.forum.lightblue.io/Query-language-tweak-From-array-element-is-it-parent-or-parent-parent-tp159.html
To start a new topic under lightblue-dev, email [hidden email]
To unsubscribe from lightblue-dev, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Query language tweak? From array element, is it $parent or $parent.parent

bserdar
If we discussed this before, apparently we decided to treat array
elements as first-class citizens.

I'll change the path resolution to "not require" the additional element stage.

On Mon, Sep 22, 2014 at 6:51 PM, jewzaam [via lightblue-dev]
<[hidden email]> wrote:

> Is this a problem with interpretation of $parent? Makes sense to have parent
> of array elements resolve to the parent of the array. I think we've had this
> discussion before. Sounds familiar at least.
>
> On Sep 22, 2014 4:04 PM, "bserdar [via lightblue-dev]" <[hidden email]>
> wrote:
>>
>> Here's some annoying quirk of the query language:
>>
>>  We interpret association queries relative to the node they're defined.
>> So, if an association field is defined as:
>>
>>  ...
>>  some_assoc_field : { "type" ; 'reference",
>>                                     "entity": "X",
>>                                     "query": { "field":"_id", "op":"=",
>> "rfield";"$parent.x_id" }
>>                                  }
>> ...
>>
>>
>> The intend is to equate the _id of X to the x_id in the parent entity. The
>> query fields are interpreted with respect to the node it is defined.
>>
>> When we process this metadata, we replace that association field with an
>> array. The array elements become object defined as the metadata of the
>> associated entity. But, we treat arrays as two-level objects. So. the array
>> "some_assoc_field" has children 0,1,2.... (the elements of the array), and
>> then "some_assoc_field.0" has the fields of entity X. Because of this, the
>> correct association query is:
>>
>>    $parent.$parent.x_id
>>
>> instead of
>>
>>    $parent.x_id
>>
>> If I interpret the fields wrt the array field itself (some_assoc_field),
>> then
>>
>>    $parent.x_id
>>
>> would refer to the correct field, but the _id reference to X becomes:
>>
>>     *._id
>>
>> because array elements are the children of array field.
>>
>> So, I can think of a couple of options:
>>
>>  1) Keep it as is. $parent.$parent will be used to access parent entity
>> fields
>>  2) Tweak array element interpretation so that $parent from an array
>> element doesn't go to the array field, but to the parent of the array field.
>> So, $parent.x_id will refer to the parent entity array field, and _id will
>> refer to the X._id. The inconsistency here is that you refer to an array
>> element field as:
>>     arrayField.*.someField
>> but from someField, if you have $parent.x, it refers to a field x at the
>> same level as arrayField.
>>
>> Let me know your preference. Is there a third option? Let me know that as
>> well if you can think of one.
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://dev.forum.lightblue.io/Query-language-tweak-From-array-element-is-it-parent-or-parent-parent-tp159.html
>> To start a new topic under lightblue-dev, email [hidden email]
>> To unsubscribe from lightblue-dev, click here.
>> NAML
>
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://dev.forum.lightblue.io/Query-language-tweak-From-array-element-is-it-parent-or-parent-parent-tp159p160.html
> To start a new topic under lightblue-dev, email
> [hidden email]
> To unsubscribe from lightblue-dev, click here.
> NAML