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.
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 | belongs |
Define the inverse of a hasOne/hasMany relationship. |
| Method | belongs |
Define a many-to-many relationship backed by a pivot table. |
| Method | get |
Return an already-resolved relationship result. |
| Method | has |
Define a one-to-many relationship owned by the related table. |
| Method | has |
Define a one-to-one relationship owned by the related table. |
| Method | relation |
Report whether a relationship result has already been resolved. |
| Method | set |
Store an already-resolved relationship result. |
| Class Variable | __slots__ |
Undocumented |
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 Model | Model class the relationship targets. |
foreignstr or None, optional | Column on this model referencing the related row; defaults to snake_case(RelatedClass) + "_id". |
ownerstr or None, optional | Column on the related table identifying the owning row; defaults to the related model's primary key. |
| Returns | |
BelongsToRelation | Relationship query builder bound to this instance. |
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 Model | Model class the relationship targets. |
table:str or None, optional | Pivot table name; defaults to both model names in snake_case, joined by "_" in alphabetical order. |
foreignstr or None, optional | Pivot column referencing this model; defaults to snake_case(ThisClass) + "_id". |
relatedstr or None, optional | Pivot column referencing the related row; defaults to snake_case(RelatedClass) + "_id". |
parentstr or None, optional | Column on this model matched against foreign_pivot_key; defaults to this model's primary key. |
relatedstr or None, optional | Column on the related table matched against related_pivot_key; defaults to the related model's primary key. |
| Returns | |
BelongsToManyRelation | Relationship query builder bound to this instance. |
Return an already-resolved relationship result.
| Parameters | |
name:str | Relationship name. |
default:Any, optional | Value returned when the relationship was never loaded. |
| Returns | |
Any | Stored relationship result, or the default when unset. |
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 Model | Model class the relationship targets. |
foreignstr or None, optional | Column on the related table referencing this model; defaults to snake_case(ThisClass) + "_id". |
localstr or None, optional | Column on this model compared against the foreign key; defaults to this model's primary key. |
| Returns | |
HasManyRelation | Relationship query builder bound to this instance. |
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 Model | Model class the relationship targets. |
foreignstr or None, optional | Column on the related table referencing this model; defaults to snake_case(ThisClass) + "_id". |
localstr or None, optional | Column on this model compared against the foreign key; defaults to this model's primary key. |
| Returns | |
HasOneRelation | Relationship query builder bound to this instance. |
Report whether a relationship result has already been resolved.
| Parameters | |
name:str | Relationship name. |
| Returns | |
bool | True when the relationship was already loaded, whether
by eager loading or a prior setRelation call. |