Type.add(self, *args, **kwargs) -> Instance

Adds a new object to the type and returns an Instance representing that object. Must be used in a rule or query context.


*argsAnyAny additional types to which the object being added belongs.
*kwargsAnyProperties that uniquely identify the object being added.


An Instance object.


import relationalai as rai

model = rai.Model("books")

# Create a type named Book.
Book = model.Type("Book")

# Add a book instance to the Book type.
with model.rule():
    Book.add(name="Foundation", author="Isaac Asimov")

You may add an object to multiple types simultaneously by passing the type objects as positional parameters:

Fiction = model.type("Fiction")
SciFi = model.Type("SciFi")

with model.rule():
    Book.add(Fiction, SciFi, name="Foundation", author="Isaac Asimov")

This rule adds a new book object and classifies it as fiction and sci-fi.

Properties set with .add() are hashed internally to uniquely identify the object in the model. These internal IDs are the values produced by Instance objects:

with model.query() as select:
    book = Book()
    reponse = select(book)

# Output:
#                      book
# 0  iikm1rGdR3jWQtS2XVUZDg

See Also#