Relatude Help

9.1 Relation lists are ordered

A many end is a list, not a set: its order is stored, and you can change it. Use it for hand-curated sequences, such as a running order, a menu or a gallery, instead of a SortIndex property.

  • AddRelation appends at the bottom.
  • Reads follow the stored order: foreach, Get() and included ends all return it.
  • No duplicates. Relating a pair that is already related throws, and so does removing a pair that is not related.
  • Each end has its own order. In a many-to-many relation, the order of attendees on an event and the order of events on an attendee are separate.

A one end holds at most one node, so ordering applies to many ends only.

The MoveRelation… family

These methods change the order without adding or removing anything:

Method Moves
MoveRelation(from, end, item, offset) item by offset places: negative toward the top, positive toward the bottom
MoveRelationToTop(from, end, item) item to the top
MoveRelationToBottom(from, end, item) item to the bottom
MoveRelationBefore(from, end, item, anchor) item just before anchor, another node in the list
MoveRelationAfter(from, end, item, anchor) item just after anchor
SetRelationOrder(from, end, itemsInOrder) the whole list into the given order
db.MoveRelationToTop<IVenue>(venue, v => v.Events, headliner);
db.MoveRelation<IVenue>(venue, v => v.Events, ev, offset: -1);
db.MoveRelationBefore<IVenue>(venue, v => v.Events, ev, anchor: other);
db.SetRelationOrder<IVenue>(venue, v => v.Events, orderedEvents);

// relate and position in one transaction
db.CreateTransaction()
  .AddRelation<IVenue>(venue, v => v.Events, ev)
  .MoveRelationToTop<IVenue>(venue, v => v.Events, ev)
  .Execute();
  • Pass several items and they move as a block that keeps its own order.
  • Positions are clamped. Moving past the top or the bottom never throws.
  • SetRelationOrder must list exactly the nodes related now. It only reorders.
  • Never reorder by removing and adding again. That is two writes, and the add lands at the bottom.

All of them are on NodeStore and on Transaction, where calls chain. Besides nodes and an expression, they take Guid ids or a raw property id; Transaction also takes internal int ids.