You can define has_many and has_one associations on ActiveGraph::Node models to simplify querying and creating relationships. Associations can be directed :in, :out, or :both.
Association Types
:in: Incoming relationships.:out: Outgoing relationships.:both: Both incoming and outgoing relationships.
Configuration Options
type: The relationship type (e.g., :author).origin: The name of the relationship on the target model that points back to this model.model_class: The class of the target nodes. Can be a single class, an array of classes, or false to match any node.chainable: true: For has_one associations, this returns an AssociationProxy instead of the object itself, allowing you to continue chaining even if the result is nil.
class Post
include ActiveGraph::Node
has_many :in, :comments, origin: :post
has_one :out, :author, type: :author, model_class: :Person
end
# Querying
post.comments.to_a # Array of comments
comment.post # Post object
comment.post(chainable: true) # Association proxy object