Solved

How to traverse relationships in Liquid?

  • 20 October 2023
  • 2 replies
  • 49 views

I have an organisation object (equivalent to the default Company one) that is attached to several people.

In Liquid, I’m able to display the organisation name of a user by using `{{ objects.organisations[0].name }}`.

Now, I’d like to retrieve the “number of users that belongs to an organisation” from Liquid. The goal being to be able to write the number of colleagues of a user in an email.

I’d expect something like this: `{{ objects.organisations[0].people | size }}` 

 

How can I achieve this please?

icon

Best answer by Jordan 21 October 2023, 01:48

View original

2 replies

Userlevel 2
Badge

Hey @ValentinHervieu 

 

At this time, only attribute values stored on the Object can be referenced with Liquid. So if you were to set and increment the number of a “people” attribute on the Object, you could reference it with {{ objects.organisations[0].people }}, but this isn’t something that can be automatically tracked and referenced.

 

We still need to see whether or not “relationship attributes” (on our roadmap) will enable something like this. Just in case it isn’t already part of the planned feature set, we’re creating a feature request for this. 🗳️

 

Don’t hesitate to let us know your feature ideas by submitting them via the “Need help” dropdown or via email to product@customer.io.

 

 

Thanks for the answer. Indeed, storing the number of people directly on the organisation object is the workaround I’m currently using.

Looking forward to the improvements on that side as we are trying to rely more and more on Objects and Relationships.

Reply