not_found()#

relationalai.Model
Model.not_found(dynamic: bool = False) -> Context

Filters objects to only those that do not satisfy the conditions in the .not_found() context. Must be used in a rule or query context.

Parameters#

NameTypeDescription
dynamicboolWhether or not the context is dynamic. Dynamic queries support Python control flow as macros. See Context for more information.

Returns#

A Context object.

Example#

Model.not_found() is a context manager and should be called in a with statement. It must be called from within a rule or query context:

import relationalai as rai

model = rai.Model("people")
Person = model.Type("Person")

with model.rule():
    Person.add(name="Fred", age=22)
    Person.add(name="Janet", age=63)

# `model.not_found()` is always called in a nested `with` block
# inside of a `model.rule()` or `model.query()` context.
with model.query() as select:
    person = Person()
    # Restrict `person` to objects that do not have
    # a `name` property set to the string `"Janet"`.
    with model.not_found():
        person.name == "Janet"
    response = select(person.name)

print(response.results)
# Output:
#    name
# 0  Fred

See Also#