__getattribute__()#

relationalai.ContextSelect
#ContextSelect.__get_attribute__(name: str) -> Instance

Gets an InstanceProperty that produces property values of objects added to a ContextSelect object. Must be used in a rule or query context.

Parameters#

NameTypeDescription
namestrThe name of the property to get.

Returns#

An Instance object.

Example#

#import relationalai as rai

model = rai.Model("books")
Book = model.Type("Book")

# Add some books to the model.
with model.rule():
    Book.add(title="Foundation", author="Isaac Asimov", year=1951)
    Book.add(title="Humble Pi", author="Matt Parker", year=2019)

# Get all books authored by Isaac Asimov or published after 1950.
with model.query() as select:
    book = Book()
    with model.match(multiple=True) as matched:
        with book.author == "Isaac Asimov":
            matched.add(book, message="authored by Asimov")
        with book.year > 1950:
            matched.add(book, message="published after 1950")
    # Select the `.title`, `.author`, and `.message` properties of
    # objects in `matched`. Note that `.title` and `.author` were created
    # by `Book.add()`, whereas `.message` was created by `matched.add()`.
    response = select(matched.title, matched.author, matched.message)

print(response.results)
# Output:
#         title        author                     v
# 0  Foundation  Isaac Asimov    authored by Asimov
# 1  Foundation  Isaac Asimov  published after 1950
# 2   Humble Pi   Matt Parker  published after 1950

See Also#