ORIONIS API REFERENCE

THE ORIONIS API

Build with clarity.

Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.

class documentation

class RelationsMixin: (source)

Known subclasses: orionis.orm.Model

View In Hierarchy

Relationship factories and loaded-relation storage for every model.

Concrete models declare relationships as regular instance methods calling the factories below, mirroring Eloquent:

class User(Model):
    def posts(self):
        return self.hasMany(Post)

    def profile(self):
        return self.hasOne(Profile)

Instance methods (rather than class-body descriptors) are used deliberately: a descriptor such as posts = hasMany(Post) would be evaluated while the class body executes, which breaks the moment two related models reference each other from separate modules (or even from the same module when one is declared after the other) -- a forward-reference problem regular methods sidestep entirely, since their body only runs once every involved class already exists.

The mixin also owns the _relations mapping every model instance carries, used to cache eager-loaded results (~orionis.orm.query.builder.ModelQueryBuilder.withRelations).

Method belongsTo Define the inverse of a hasOne/hasMany relationship.
Method belongsToMany Define a many-to-many relationship backed by a pivot table.
Method getRelation Return an already-resolved relationship result.
Method hasMany Define a one-to-many relationship owned by the related table.
Method hasOne Define a one-to-one relationship owned by the related table.
Method relationLoaded Report whether a relationship result has already been resolved.
Method setRelation Store an already-resolved relationship result.
Class Variable __slots__ Undocumented
def belongsTo(self, related: type[TRelated], foreign_key: str | None = None, owner_key: str | None = None) -> BelongsToRelation[TRelated]: (source)

Define the inverse of a hasOne/hasMany relationship.

Parameters
related:type of ModelModel class the relationship targets.
foreign_key:str or None, optionalColumn on this model referencing the related row; defaults to snake_case(RelatedClass) + "_id".
owner_key:str or None, optionalColumn on the related table identifying the owning row; defaults to the related model's primary key.
Returns
BelongsToRelationRelationship query builder bound to this instance.
def belongsToMany(self, related: type[TRelated], table: str | None = None, foreign_pivot_key: str | None = None, related_pivot_key: str | None = None, parent_key: str | None = None, related_key: str | None = None) -> BelongsToManyRelation[TRelated]: (source)

Define a many-to-many relationship backed by a pivot table.

Parameters
related:type of ModelModel class the relationship targets.
table:str or None, optionalPivot table name; defaults to both model names in snake_case, joined by "_" in alphabetical order.
foreign_pivot_key:str or None, optionalPivot column referencing this model; defaults to snake_case(ThisClass) + "_id".
related_pivot_key:str or None, optionalPivot column referencing the related row; defaults to snake_case(RelatedClass) + "_id".
parent_key:str or None, optionalColumn on this model matched against foreign_pivot_key; defaults to this model's primary key.
related_key:str or None, optionalColumn on the related table matched against related_pivot_key; defaults to the related model's primary key.
Returns
BelongsToManyRelationRelationship query builder bound to this instance.
def getRelation(self, name: str, default: Any = None) -> Any: (source)

Return an already-resolved relationship result.

Parameters
name:strRelationship name.
default:Any, optionalValue returned when the relationship was never loaded.
Returns
AnyStored relationship result, or the default when unset.
def hasMany(self, related: type[TRelated], foreign_key: str | None = None, local_key: str | None = None) -> HasManyRelation[TRelated]: (source)

Define a one-to-many relationship owned by the related table.

Parameters
related:type of ModelModel class the relationship targets.
foreign_key:str or None, optionalColumn on the related table referencing this model; defaults to snake_case(ThisClass) + "_id".
local_key:str or None, optionalColumn on this model compared against the foreign key; defaults to this model's primary key.
Returns
HasManyRelationRelationship query builder bound to this instance.
def hasOne(self, related: type[TRelated], foreign_key: str | None = None, local_key: str | None = None) -> HasOneRelation[TRelated]: (source)

Define a one-to-one relationship owned by the related table.

Parameters
related:type of ModelModel class the relationship targets.
foreign_key:str or None, optionalColumn on the related table referencing this model; defaults to snake_case(ThisClass) + "_id".
local_key:str or None, optionalColumn on this model compared against the foreign key; defaults to this model's primary key.
Returns
HasOneRelationRelationship query builder bound to this instance.
def relationLoaded(self, name: str) -> bool: (source)

Report whether a relationship result has already been resolved.

Parameters
name:strRelationship name.
Returns
boolTrue when the relationship was already loaded, whether by eager loading or a prior setRelation call.
def setRelation(self, name: str, value: Any) -> Model: (source)

Store an already-resolved relationship result.

Parameters
name:strRelationship name.
value:AnyResolved relationship result (a model, None, or a Collection, depending on the relationship kind).
Returns
ModelThe same instance, enabling fluent chaining.
__slots__: tuple = (source)
overridden in orionis.orm.Model

Undocumented