Correct spelling mistakes (#1163)

Co-authored-by: collerek <collerek@gmail.com>
This commit is contained in:
Edward Betts
2023-08-15 10:56:19 +01:00
committed by GitHub
parent 930e8fb2e7
commit eea2ba0bef
24 changed files with 48 additions and 48 deletions

View File

@ -420,7 +420,7 @@ async def filter_and_sort():
async def subset_of_columns():
# to exclude some columns from loading when querying the database
# you can use fileds() method
# you can use fields() method
hobbit = await Book.objects.fields(["title"]).get(title="The Hobbit")
# note that fields not included in fields are empty (set to None)
assert hobbit.year is None

View File

@ -37,7 +37,7 @@ class User(ormar.Model):
category: str = ormar.String(max_length=255, default="User")
```
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model wil still validate.
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model will still validate.
If the field is nullable you don't have to include it in payload during creation as well as in response, so given example above you can:
@ -75,9 +75,9 @@ async def create_user3(user: RequestUser): # use the generated model here
!!!Warning
The `get_pydantic` method generates all models in a tree of nested models according to an algorithm that allows to avoid loops in models (same algorithm that is used in `dict()`, `select_all()` etc.)
That means that nested models won't have reference to parent model (by default ormar relation is biderectional).
That means that nested models won't have reference to parent model (by default ormar relation is bidirectional).
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurance will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurrence will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
#### Mypy and type checking

View File

@ -36,7 +36,7 @@ class User(ormar.Model):
category: str = ormar.String(max_length=255, default="User")
```
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model wil still validate.
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model will still validate.
If the field is nullable you don't have to include it in payload during creation as well as in response, so given example above you can:
@ -143,7 +143,7 @@ async def create_user(user: User):
return await user.save()
```
Note that you can go in deeper models with double underscore, and if you wan't to exclude multiple fields from nested model you need to prefix them with full path.
Note that you can go in deeper models with double underscore, and if you want to exclude multiple fields from nested model you need to prefix them with full path.
In example `response_model_exclude={"category__priority", "category__other_field", category__nested_model__nested_model_field}` etc.
!!!Note
@ -215,9 +215,9 @@ async def create_user3(user: User):
!!!Warning
The `get_pydantic` method generates all models in a tree of nested models according to an algorithm that allows to avoid loops in models (same algorithm that is used in `dict()`, `select_all()` etc.)
That means that nested models won't have reference to parent model (by default ormar relation is biderectional).
That means that nested models won't have reference to parent model (by default ormar relation is bidirectional).
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurance will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurrence will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
### Separate `pydantic` model

View File

@ -222,7 +222,7 @@ It will add both: validation in `pydantic` model and will display available opti
therefore it will be available in docs of `fastapi`.
If you still want to use `Enum` in your application you can do this by passing a `Enum` into choices
and later pass value of given option to a given field (note tha Enum is not JsonSerializable).
and later pass value of given option to a given field (note that Enum is not JsonSerializable).
```python
# note that imports and endpoints declaration

View File

@ -238,7 +238,7 @@ def test_excluding_property_field_in_endpoints2():
"last_name",
"created_date",
]
# despite being decorated with property_field if you explictly exclude it it will be gone
# despite being decorated with property_field if you explicitly exclude it it will be gone
assert response.json().get("full_name") is None
# <==related of code removed for clarity==>

View File

@ -394,7 +394,7 @@ class Bus2(Car2):
```
`Ormar` automatically modifies related_name of the fields to include the **table** name
of the children models. The dafault name is original related_name + '_' + child table name.
of the children models. The default name is original related_name + '_' + child table name.
That way for class Truck2 the relation defined in
`owner: Person = ormar.ForeignKey(Person, related_name="owned")` becomes `owned_trucks2`
@ -509,13 +509,13 @@ class Category(DateFieldsModel, AuditModel):
code: int = ormar.Integer()
# Note that now the update fields in Category are gone in all places -> ormar fields, pydantic fields and sqlachemy table columns
# so full list of available fileds in Category is: ["created_by", "created_date", "id", "name", "code"]
# so full list of available fields in Category is: ["created_by", "created_date", "id", "name", "code"]
```
Note how you simply need to provide field names and it will exclude the parent field regardless of from which parent model the field is coming from.
!!!Note
Note that if you want to overwrite a field in child model you do not have to exclude it, simpy overwrite the field declaration in child model with same field name.
Note that if you want to overwrite a field in child model you do not have to exclude it, simply overwrite the field declaration in child model with same field name.
!!!Warning
Note that this kind of behavior can confuse mypy and static type checkers, yet accessing the non existing fields will fail at runtime. That's why splitting the base classes is preferred.

View File

@ -29,7 +29,7 @@ The benefit of using construct is the speed of execution due to skipped validati
!!!warning
Bear in mind that due to skipped validation the `construct` method does not perform any conversions, checks etc.
So it's your responsibility to provide tha data that is valid and can be consumed by the database.
So it's your responsibility to provide that data that is valid and can be consumed by the database.
The only two things that construct still performs are:
@ -45,7 +45,7 @@ therefore it's listed here for clarity.
Explanation of dict parameters:
### include (`ormar` modifed)
### include (`ormar` modified)
`include: Union[Set, Dict] = None`
@ -630,7 +630,7 @@ to_save = {
},
],
}
# initializa whole tree
# initialize whole tree
department = Department(**to_save)
# save all at once (one after another)

View File

@ -93,7 +93,7 @@ assert album == album2
!!!warning
Despite being a equivalent row from database the `album` and `album2` in
example above are 2 different python objects!
Updating one of them will not refresh the second one until you excplicitly load() the
Updating one of them will not refresh the second one until you explicitly load() the
fresh data from db.
!!!note

View File

@ -583,7 +583,7 @@ books = (
`get(*args, **kwargs) -> Model`
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
When any args and/or kwargs are passed it's a shortcut equivalent to calling `filter(*args, **kwargs).get()`
@ -713,7 +713,7 @@ Ordering in sql will be applied in order of names you provide in order_by.
will result in 2 rows of result:
```
MODEL: 1 - Child Models: [3, 1] # encountered first in result, all children rows combined
MODEL: 2 - Child Modles: [2]
MODEL: 2 - Child Models: [2]
```
The main model will never duplicate in the result

View File

@ -33,7 +33,7 @@ To chain related `Models` relation use double underscores between names.
!!!note
If you are coming from `django` note that `ormar` `select_related` differs ->
in `django` you can `select_related`
only singe relation types, while in `ormar` you can select related across `ForeignKey`
only single relation types, while in `ormar` you can select related across `ForeignKey`
relation, reverse side of `ForeignKey` (so virtual auto generated keys) and `ManyToMany`
fields (so all relations as of current version).

View File

@ -115,7 +115,7 @@ tracks = await Track.objects.offset(1).limit(1).all()
`get(**kwargs) -> Model`
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
If no criteria is set it will return the last row in db sorted by pk.
(The criteria cannot be set also with filter/exclude).

View File

@ -23,7 +23,7 @@ Following methods allow you to load data from the database.
`get(*args, **kwargs) -> Model`
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk column.
@ -99,7 +99,7 @@ assert album == album2
!!!warning
Despite being an equivalent row from database the `album` and `album2` in
example above are 2 different python objects!
Updating one of them will not refresh the second one until you excplicitly load() the
Updating one of them will not refresh the second one until you explicitly load() the
fresh data from db.
!!!note

View File

@ -100,7 +100,7 @@ for those models in fields
```python hl_lines="1"
all_cars = await Car.objects.select_related('manufacturer').fields('id').fields(
['name']).all()
# all fiels from company model are selected
# all fields from company model are selected
assert all_cars[0].manufacturer.name == 'Toyota'
assert all_cars[0].manufacturer.founded == 1937
```
@ -263,7 +263,7 @@ for car in all_cars:
# models selected in select_related but with no columns in fields list implies all fields
all_cars = await Car.objects.select_related('manufacturer').exclude_fields('year').exclude_fields(
['gear', 'gearbox_type']).all()
# all fiels from company model are selected
# all fields from company model are selected
assert all_cars[0].manufacturer.name == 'Toyota'
assert all_cars[0].manufacturer.founded == 1937

View File

@ -198,7 +198,7 @@ To customize the names of fields/relation in Through model now you can use new p
Example:
```python
... # course declaration ommited
... # course declaration omitted
class Student(ormar.Model):
class Meta:
database = database

View File

@ -511,7 +511,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.
* By default `Through` model relation names default to related model name in lowercase.
So in example like this:
```python
... # course declaration ommited
... # course declaration omitted
class Student(ormar.Model):
class Meta:
database = database
@ -538,7 +538,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.
Example:
```python
... # course declaration ommited
... # course declaration omitted
class Student(ormar.Model):
class Meta:
database = database
@ -672,7 +672,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.
* Add 4 new signals -> `pre_relation_add`, `post_relation_add`, `pre_relation_remove` and `post_relation_remove`
* The newly added signals are emitted for `ManyToMany` relations (both sides)
and reverse side of `ForeignKey` relation (same as `QuerysetProxy` is exposed).
* Signals recieve following args: `sender: Type[Model]` - sender class,
* Signals receive following args: `sender: Type[Model]` - sender class,
`instance: Model` - instance to which related model is added, `child: Model` - model being added,
`relation_name: str` - name of the relation to which child is added,
for add signals also `passed_kwargs: Dict` - dict of kwargs passed to `add()`
@ -834,7 +834,7 @@ that most of the `ormar` functions are working your database **CREATED with orma
* **Breaking:** During model construction if `Meta` class of the `Model` does not
include `metadata` or `database` now `ModelDefinitionError` will be raised instead of generic `AttributeError`.
* **Breaking:** `encode/databases` used for running the queries does not have a connection pool
for sqlite backend, meaning that each querry is run with a new connection and there is no way to
for sqlite backend, meaning that each query is run with a new connection and there is no way to
enable enforcing ForeignKeys constraints as those are by default turned off on every connection.
This is changed in `ormar` since >=0.9.0 and by default each sqlite3 query has `"PRAGMA foreign_keys=1;"`
run so now each sqlite3 connection by default enforces ForeignKey constraints including cascades.
@ -998,7 +998,7 @@ so now you can use those methods directly from relation
* Model is saved after adding/removing `ManyToMany` related objects (through model instance auto saved/deleted)
* Model is **not** saved after change of any own field (including pk as `Model.pk` alias)
* Model is **not** saved after adding/removing `ForeignKey` related object (fk column not saved)
* Model is **not** saved after instantation with `__init__` (w/o `QuerySet.create` or before calling `save`)
* Model is **not** saved after instantiation with `__init__` (w/o `QuerySet.create` or before calling `save`)
* Added `Model.upsert(**kwargs)` that performs `save()` if pk not set otherwise `update(**kwargs)`
* Added `Model.save_related(follow=False)` that iterates all related objects in all relations and checks if they are saved. If not it calls `upsert()` on each of them.
* **Breaking:** added raising exceptions if `add`-ing/`remove`-ing not saved (pk is None) models to `ManyToMany` relation

View File

@ -8,7 +8,7 @@ To use transactions use `database.transaction` as async context manager:
```python
async with database.transaction():
# everyting called here will be one transaction
# everything called here will be one transaction
await Model1().save()
await Model2().save()
...

View File

@ -59,7 +59,7 @@ for car in all_cars:
# models selected in select_related but with no columns in fields list implies all fields
all_cars = await Car.objects.select_related('manufacturer').exclude_fields('year').exclude_fields(
['gear', 'gearbox_type']).all()
# all fiels from company model are selected
# all fields from company model are selected
assert all_cars[0].manufacturer.name == 'Toyota'
assert all_cars[0].manufacturer.founded == 1937

View File

@ -254,7 +254,7 @@ async def filter_and_sort():
async def subset_of_columns():
# to exclude some columns from loading when querying the database
# you can use fileds() method
# you can use fields() method
hobbit = await Book.objects.fields(["title"]).get(title="The Hobbit")
# note that fields not included in fields are empty (set to None)
assert hobbit.year is None

View File

@ -28,7 +28,7 @@ class PrefetchQueryMixin(RelationMixin):
:param parent_model: related model that the relation lead to
:type parent_model: Type[Model]
:param target_model: model on which query should be perfomed
:param target_model: model on which query should be performed
:type target_model: Type[Model]
:param reverse: flag if the relation is reverse
:type reverse: bool

View File

@ -64,7 +64,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
Constructed with ModelMetaclass which in turn also inherits pydantic metaclass.
Abstracts away all internals and helper functions, so final Model class has only
the logic concerned with database connection and data persistance.
the logic concerned with database connection and data persistence.
"""
__slots__ = (

View File

@ -223,7 +223,7 @@ class Query:
:param expr: select expression before clauses
:type expr: sqlalchemy.sql.selectable.Select
:return: expresion with all present clauses applied
:return: expression with all present clauses applied
:rtype: sqlalchemy.sql.selectable.Select
"""
expr = FilterQuery(filter_clauses=self.filter_clauses).apply(expr)

View File

@ -926,7 +926,7 @@ class QuerySet(Generic[T]):
async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
"""
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk.
@ -947,7 +947,7 @@ class QuerySet(Generic[T]):
async def get(self, *args: Any, **kwargs: Any) -> "T": # noqa: CCR001
"""
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk.

View File

@ -361,7 +361,7 @@ class QuerysetProxy(Generic[T]):
async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
"""
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk.
@ -386,7 +386,7 @@ class QuerysetProxy(Generic[T]):
async def get(self, *args: Any, **kwargs: Any) -> "T":
"""
Get's the first row from the db meeting the criteria set by kwargs.
Gets the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk.
@ -523,7 +523,7 @@ class QuerysetProxy(Generic[T]):
"""
Combination of create and get methods.
Tries to get a row meeting the criteria fro kwargs
Tries to get a row meeting the criteria for kwargs
and if `NoMatch` exception is raised
it creates a new one with given kwargs and _defaults.

View File

@ -101,7 +101,7 @@ types-pkg-resources = "^0.1.3"
types-requests = "^2.31.0"
types-toml = "^0.10.8"
# Documantation
# Documentation
mkdocs = "^1.5.2"
mkdocs-material = ">=8.1.2,<9.2"
mkdocs-material-extensions = "^1.1"