Skip to main content

Relationships

# Leo acted in Inception
db.records.attach(
source=leo,
target=inception,
options={"type": "ACTED_IN"}
)

# Detach
db.records.detach(
source=leo,
target=inception,
options={"type": "ACTED_IN"}
)

Attach

attach()

# With direction
db.records.attach(
source=movie,
target=actor,
options={"type": "STARS_IN", "direction": "out"}
)

# One-to-many (target list)
db.records.attach(
source=movie,
target=[actor1, actor2, actor3],
options={"type": "STARS_IN"}
)

Detach

detach()

db.records.detach(
source=movie,
target=actor,
options={"type": "STARS_IN"}
)

Direction

ValueMeaning
"out"source → target
"in"target → source

With a transaction

tx = db.tx.begin()
try:
db.records.attach(source=movie, target=actor, options={"type": "STARS_IN"}, transaction=tx)
tx.commit()
except Exception:
tx.rollback()
raise

For traversal in queries, see Get Records — Relationship traversal.