Relevance "Joining"

(imported topic written by Pol.o.Currain)

Hi guys,

I have a question - how can I use a value I get from one object to look up another?

I’ll show you what I mean:

Let’s say I have an action on the system whose name contains the ID of another action, and I want to write a single query to return me details about both, how would I do that? I quickly run into the issue of nested "it"s (where I can’t use the “it” for the name of the action in the whose clause for the second lookup)

e.g.

Let’s say I have an action whose ID is 123, and it’s name is “456” (I’m just going to say for convenience sake that the name is purely the ID of the “other” action to save on parsing, but it would probably contain some text as well).

I want to write a query that will return me the name of the action that is doing the referencing (i.e. “456”), and also the name of the action with the ID 456.

If I try to do something like this, the “it” always refers to the object to the left of the nearest “whose” clause:

(
 name of bes action whose( id of it = name of it), name of it
)
of bes action
whose 
(
  id of it = 123
)

I’m guessing this is just a limitation, but asking the question anyway in case there’s a pattern I can follow here to achieve this.

(imported comment written by MattPeterson)

This does seem like a limitation, I’ve faced similar problems. The only way I can think to solve this one would be to reference your action ID twice, which I know if not ideal, especially if your getting your ID from a long relevance expression.

name of bes actions whose (id of it = 123), name of bes action whose (id of it = (name of bes action whose (id of it = 123) as integer))

(imported comment written by JasonWalker)

I’m at home without presentation debugger, only FixletDebugger, but the use of “item X” might help. The first few lines here are examples of using sets (separate answers, built by separating terms with semicolons) vs tuples (multiple properties in one answer, separated by commas, and indexable as “item #”). The last few dealing with bes actions I can’t test from here but I think are in the right direction.

q: (“one”;“two”;“three”)

A: one

A: two

A: three

T: 0.020 ms

q: (3,“three”;4,“four”)

A: 3, three

A: 4, four

T: 0.028 ms

q: items 0 of (3,“three”;4,“four”)

A: 3

A: 4

T: 0.033 ms

q: items 1 of (3,“three”;4,“four”)

A: three

A: four

T: 0.029 ms

q: (“one”;“two”;“three”), (3,“three”;4,“four”)

A: one, ( 3, three )

A: one, ( 4, four )

A: two, ( 3, three )

A: two, ( 4, four )

A: three, ( 3, three )

A: three, ( 4, four )

T: 0.046 ms

// NOTE that this gave a cross-product of the elements of both sets, so for an inspector with many results like ‘bes actions’, you’ll want to reduce both sets as much as possible before combining them in tuples.

q: items 0 of ((“one”;“two”;“three”), (3,“three”;4,“four”))

A: one

A: one

A: two

A: two

A: three

A: three

T: 0.040 ms

q: items 0 of items 1 of ((“one”;“two”;“three”), (3,“three”;4,“four”))

A: 3

A: 4

A: 3

A: 4

A: 3

A: 4

T: 0.044 ms

//Look for the elements in common…

q: ((“one”;“two”;“three”), (3,“three”;4,“four”)) whose (item 1 of item 1 of it = item 0 of it)

A: three, ( 3, three )

T: 0.053 ms

// if you want to combine these back into a single result set you can do something like

q: elements of set of (items 0 of it; items 1 of items 1 of it) of ((“one”;“two”;“three”;“four”), (3,“three”;4,“four”)) whose (item 1 of item 1 of it = item 0 of it)

A: four

A: three

T: 0.091 ms

// I think this will do what you’re looking for…

((bes actions whose (id of it = “123”)), bes actions) whose (name of item 1 of it as string contains id of item 0 of it as string)

items 1 of ((bes actions whose (id of it = “123”)), bes actions) whose (name of item 1 of it as string contains id of item 0 of it as string)

elements of set of (items 0 of it; items 1 of it) of ((bes actions whose (id of it = “123”)), bes actions) whose (name of item 1 of it as string contains id of item 0 of it as string)

(imported comment written by Pol.o.Currain)

Thanks a lot for that Jason - you’re right! :slight_smile:

That’s got me unblocked, so thanks a lot for coming back to me on this!