[DONE] Siblings as Children of Parents: filter self

Bit of a confusing title, but basically:

When using self-relations in a type, the uni-directional type is often a great fit for the relation (that is - not for situations where I’d want the basic / undirected / bi-directed siblings), where the concept of “parent” entities and “child” entities exists, but they really are all the same type.

In such scenarios, it’s often nice to see automatic sibling links, through a lookup: using the children of parents. The problem is that this results in including the entity itself as one of its own siblings.

Is there a way to include these auto-siblings while filtering the self? This could be doable through the API but seems like the lookup version is already so close.

Thanks!

2 Likes

I think this will eventually be possible by using a formula field, when the option to refer to self in a formula becomes possible (it was requested here at some point but I can’t find it at the moment).

So for example, a type with a relationship to itself (parent-children) can have a lookup field (Siblings) which is:
Siblings: Parent -> Children
which as you say, returns all children including itself.

But then use a formula that filters out itself:

Siblings excl : Siblings.filter(Name != this.Name)

@mdubakov @antoniokov
Is self-referring on the horizon?

1 Like

Would love to see this feature as well. I have tried to set up a “Task/Subtask” arrangement within the same Type, and this seems like it could help with that.

1 Like

This is the 4th different use case we’ve got for this in Formulas. This applies to the .Filter() function too.

We are still not sure how to implement it technically. We’ll probably do some research this autumn (not a promise, but :crossed_fingers:).

Stay tuned!

3 Likes

Is there an update on implementation of this in formulas?

I didn’t want to hijack this old thread but I thought it might be the best place to get @antoniokov 's attention.

I have a few use cases that would also benefit from this, e.g.:

  1. tracking how names of places change over time while also automatically being able to use the latest name for the entity (name record with the latest/maximum date)

  2. tracking position history of employees while also automatically being able to populate their current position (position in the positions collection with the latest/maximum date)

Keeping a record of the changes is easy: in both of these case, we can create entities (e.g. Place Name or Positions) that have start and end dates and relate them to the parent entity to keep the history of changes.

However, to get the latest name or position, then the only way I can think of is to create a formula field in the parent entity that finds the last change date:

  1. [Last Name Change] = [Place Names].Max([Start Date])

  2. [Last Position Change] = [Positions].Max([Start Date])

And then create another formula field that filters all records in the history to find the latest item (where we need this):

  1. [Current Name] = [Place Names].Filter([Start Date] = this.[Last Name Change]

  2. [Current Position] = [Positions].Filter([Start Date] = this.[Last Position Change])

I’m not sure if there is actually a way of doing this currently.

2 Likes

If I’ve understood your problem, then I think there is a way to achieve it:

  • Use a max formula to find the latest start date (as you’ve described)
  • Use a formula in the position (or place name) type to check if its start date = person’s max start date (returns a boolean with the name ‘Current’)
  • Use a formula in the person type which is positions.filter(Current = true)
    This should return a single position (assuming there is always only one with the highest start date)
2 Likes

This is fantastic, although, I feel this concept proposed above would simplify this, given that you can’t hide any of these fields.

There is one issue left in my case: filter still returns a collection object with one item rather than that item. So it is not possible to for example use the last/current name of a place as the name of the entity through “Generate Name through Formula”. Any way to resolve this?

I actually think the formula engine could use a few more functions that allow you to work with collections, e.g. sort them, extract first/last/nth/every nth item. For this example, I think being able to sort the collection on the [Start Date] in descending order and then extract the first item would be easiest solution (eliminates the need for all these other fields).

Even though the formula returns a collection, you can actually get the name of the (only) entity in the collection using
CurrentPlace.Join(Name,"")

2 Likes

Amazing! Thanks for your help with this :smile:

Referring self within the Filter(...) Formula function is here:

Getting siblings:

Parent.Children.Filter(PublicId != [This Parent].PublicId)

It’s possible to achieve the same result with [This ...] but I’d actually recommend .Sort(...) + Last() combination:

[Place Names].Sort([Start Date]).Last()
[Positions].Sort([Start Date]).Last()