Thanks for the suggestions Lahav and Kirk.
I went ahead and wrote a method that attempts to do what I want. Here’s what
it looks like:
// Method: Parse_ORDA_path
C_OBJECT($1;$vjes_EntitySelection)
C_TEXT($2;$vt_ORDAPath)
C_POINTER($3;$pt_FinalAttribute)
C_OBJECT($0;$vjes_ResolvedEntities)
C_OBJECT($vj_DataClass)
C_OBJECT($vj_DataClassAttrib)
C_COLLECTION($vc_Tokens)
C_TEXT($vt_Token)
$vjes_EntitySelection:=$1
$vt_ORDAPath:=$2
$pt_FinalAttribute:=$3
$vj_DataClass:=$vjes_EntitySelection.getDataClass()
// Make a copy of the entity selection
$vjes_ResolvedEntities:=$vjes_EntitySelection.or($vj_DataClass.newSelection())
$vc_Tokens:=Split string($vt_ORDAPath;".")
For each ($vt_Token;$vc_Tokens)
$vj_DataClassAttrib:=$vj_DataClass[$vt_Token]
Case of
: ($vj_DataClassAttrib=Null)
// Error
: ($vj_DataClassAttrib.kind="storage")
$pt_FinalAttribute->:=$vt_Token
: ($vj_DataClassAttrib.kind="relatedEntity")
$vjes_ResolvedEntities:=$vjes_ResolvedEntities[$vt_Token]
: ($vj_DataClassAttrib.kind="relatedEntities")
$vjes_ResolvedEntities:=$vjes_ResolvedEntities[$vt_Token]
End case
$vj_DataClass:=$vjes_ResolvedEntities.getDataClass()
End for each
$0:=$vjes_ResolvedEntities
And here is how I use it:
$vjes_ResolvedEntitySelection:=
Parse_ORDA_path($vjes_EntitySelection;$vt_ORDAPath;->$vt_FinalAttribute)
$vc_Attributes:=$vjes_ResolvedEntitySelection[$vt_FinalAttribute]
I think it works, and I guess it wasn’t that painful to write. Anyway, thanks
for the suggestions!
- Steve
> On May 11, 2020, at 9:49 PM, Kirk Brooks via 4D_Tech <[email protected]>
> wrote:
>
> Hi Steve,
> A couple of things to consider. You mention working with an 'entity
> selection' but then get into talking about collections. To create a
> collection from an entity selection, or only some properties of it, take a
> look at .toCollection().
> https://doc.4d.com/4Dv18R3/4D/18-R3/entitySelectiontoCollection.305-4900500.en.html
>
> This might give you want you want right there as you pass a comma delimited
> string to the method.
>
> The other approach is to simply do a query for what you need. These are
> really fast in ORDA thanks to a lot of optimization built in and it's very
> flexible.
> https://doc.4d.com/4Dv18R3/4D/18-R3/dataClassquery.305-4900853.en.html
>
> The old way of approaching these sorts of situations where you paid a big
> performance hit for multiple searches isn't nearly so true now. But it
> depends on your data. Try it and see.
>
> On Mon, May 11, 2020 at 9:04 PM Steve Slanec via 4D_Tech <
> [email protected]> wrote:
>
>> I'm trying come up with generic code that produces a projection from an
>> entity selection, and I think must be missing something obvious. I’d like
>> to perform the following statement:
>>
>> $collection:=$employees.company.country
>>
>> But as generic code. I want to be able to pass the ORDA path
>> “company.country” as a text variable so that I can change it at runtime.
>>
>> Obviously, using square bracket notation doesn’t work because square
>> brackets for entity selections are used for indexes:
>>
>> $collection:=$employees[“company.country”] // Syntax error
>>
>> So how can I do this?
>>
>> I guess I could write a method that splits the ORDA path into tokens,
>> examines each token individually, and traverses through relations if the
>> token kind is a “relation" until we get to the last token, whose kind must
>> be “storage". But I’m hoping I’m just being ignorant - it seems like a lot
>> of work for doing what object notation does so simply and elegantly.
>>
>> Using 4D v18, macOS 10.14
>>
>> Thanks for any advice!
>>
>> - Steve
>>
>>
>>
>> Steve Slanec
>> Slanecon Digital
>>
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> New Forum: https://discuss.4D.com
>> Archive: http://lists.4d.com/archives.html
>> Options: https://lists.4d.com/mailman/options/4d_tech
>> Unsub: mailto:[email protected]
>> **********************************************************************
>
>
>
> --
> Kirk Brooks
> San Francisco, CA
> ======================
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> New Forum: https://discuss.4D.com
> Archive: http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub: mailto:[email protected]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************