Skip to main content

References and Pointers

References and Pointers allow you to establish relationships between Nodes in Capela. They're essential for building complex applications.

References

A reference is a unique identifier for a Node. It lets you refer to a Node from anywhere in your application.

Creating References

Create a reference using the make_reference() method:

from builtins import Node, Field

class User(Node):
name: str = Field(default="")

def get_reference_test(self):
return self.make_reference()

Using References

References can:

  • Establish relationships between Nodes
  • Pass Nodes to functions without copying them
  • Store Node identifiers in other Nodes
from builtins import Node, Field, select

class User(Node):
name: str = Field(default="")

def get_user_by_reference(self, reference):
return select(reference)

Pointers

A Pointer is a field type that stores a reference to another Node. It establishes relationships between Nodes.

Creating Pointers

Create a Pointer field using the Pointer type:

from builtins import Node, Field, Pointer

class User(Node):
name: str = Field(default="")
profile: Pointer[Profile] = Field(default=None)