How to create custom index based on relationships?

I’d like to create a unique constraint on an order property linked to a relation.

Is this even possible? I don’t see the possibility to pick a relation field within the index builder.

Hey @gahabeen - we currently don’t support index’s built on relations. For the time being, you’ll only be able to create indexes using the table’s fields.

Ok.

In a case where I have a position property in a table and this position is relative to a relationship and I want to ensure that position + relation id is unique, @sebastian.scholl would you recommend me to add a relationId column to create my unique index ?

I’d have to make sure that it stays in sync with the relationship :confused:

That approach could work. You’d want to make sure though that you have a before.update/create trigger on the table so that you could watch for changes being made to the relationship and update the foreign key/id accordingly. Does that make sense?

It does it does. I don’t like the redundancy and additional potential point of failure but that could do the trick and prevent an extra lookup.

I’ll see to it and come back with feedback after tests.
Thanks for the feedback anyway!

For sure! Good luck.