Type.extend()#

relationalai
#Type.extend(self, *args: Type, **kwargs: Any) -> None

Assigns instances from the types passed to *args to the current Type. Optionally, you can set additional properties on the extended objects by passing keyword arguments.

Parameters#

NameTypeDescription
*argsTypeOne or more Type objects whose instances will be assigned to the current Type.
*kwargsAnyOptional keyword arguments that set additional properties on the objects added to the current Type. These properties apply to all objects being extended.

Returns#

None.

Example#

#import relationalai as rai


# =====
# SETUP
# =====

model = rai.Model("BooksModel")

# Declare Book, Fiction, Fantasy, and SciFi types.
Book = model.Type("Book")
Fiction = model.Type("Fiction")
Fantasy = model.Type("Fantasy")
SciFi = model.Type("SciFi")


# =======
# EXAMPLE
# =======

# Extend the Fiction type to include all Fantasy and SciFi objects.
Fiction.extend(Fantasy, SciFi)

# Define some Book objects.
with model.rule():
    Book.add(SciFi, name="Foundation", author="Isaac Asimov")
    Book.add(Fantasy, name="The Hobbit", author="J.R.R. Tolkien")

# Both books are instances of the Fiction type.
with model.query() as select:
    book = Fiction()
    response = select(book.name, book.author)

print(response.results)

See Also#