update docs, bump version, update releases
This commit is contained in:
@ -17,6 +17,25 @@ especially `dict()` and `json()` methods that can also accept `exclude`, `includ
|
|||||||
|
|
||||||
To read more check [pydantic][pydantic] documentation
|
To read more check [pydantic][pydantic] documentation
|
||||||
|
|
||||||
|
## construct
|
||||||
|
|
||||||
|
`construct` is a raw equivalent of `__init__` method used for construction of new instances.
|
||||||
|
|
||||||
|
The difference is that `construct` skips validations, so it should be used when you know that data is correct and can be trusted.
|
||||||
|
The benefit of using construct is the speed of execution due to skipped validation.
|
||||||
|
|
||||||
|
!!!note
|
||||||
|
Note that in contrast to `pydantic.construct` method - the `ormar` equivalent will also process the nested related models.
|
||||||
|
|
||||||
|
!!!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.
|
||||||
|
|
||||||
|
The only two things that construct still performs are:
|
||||||
|
|
||||||
|
* Providing a `default` value for not set fields
|
||||||
|
* Initialize nested ormar models if you pass a dictionary or a primary key value
|
||||||
|
|
||||||
## dict
|
## dict
|
||||||
|
|
||||||
`dict` is a method inherited from `pydantic`, yet `ormar` adds its own parameters and has some nuances when working with default values,
|
`dict` is a method inherited from `pydantic`, yet `ormar` adds its own parameters and has some nuances when working with default values,
|
||||||
@ -363,10 +382,16 @@ class Category(BaseModel):
|
|||||||
items: Optional[List[Item]]
|
items: Optional[List[Item]]
|
||||||
```
|
```
|
||||||
|
|
||||||
Of course you can use also deeply nested structures and ormar will generate it pydantic equivalent you (in a way that exclude loops).
|
Of course, you can use also deeply nested structures and ormar will generate it pydantic equivalent you (in a way that exclude loops).
|
||||||
|
|
||||||
Note how `Item` model above does not have a reference to `Category` although in ormar the relation is bidirectional (and `ormar.Item` has `categories` field).
|
Note how `Item` model above does not have a reference to `Category` although in ormar the relation is bidirectional (and `ormar.Item` has `categories` field).
|
||||||
|
|
||||||
|
!!!warning
|
||||||
|
Note that the generated pydantic model will inherit all **field** validators from the original `ormar` model, that includes the ormar choices validator as well as validators defined with `pydantic.validator` decorator.
|
||||||
|
|
||||||
|
But, at the same time all root validators present on `ormar` models will **NOT** be copied to the generated pydantic model. Since root validator can operate on all fields and a user can exclude some fields during generation of pydantic model it's not safe to copy those validators.
|
||||||
|
If required, you need to redefine/ manually copy them to generated pydantic model.
|
||||||
|
|
||||||
## load
|
## load
|
||||||
|
|
||||||
By default when you query a table without prefetching related models, the ormar will still construct
|
By default when you query a table without prefetching related models, the ormar will still construct
|
||||||
|
|||||||
@ -1,3 +1,10 @@
|
|||||||
|
# 0.10.21
|
||||||
|
|
||||||
|
## 🐛 Fixes
|
||||||
|
|
||||||
|
* Add `ormar` implementation of `construct` classmethod that allows to build `Model` instances without validating the input to speed up the whole flow, if your data is already validated [#318](https://github.com/collerek/ormar/issues/318)
|
||||||
|
* Fix for "inheriting" field validators from `ormar` model when newly created pydanic model is generated with `get_pydantic` [#365](https://github.com/collerek/ormar/issues/365)
|
||||||
|
|
||||||
# 0.10.20
|
# 0.10.20
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "ormar"
|
name = "ormar"
|
||||||
version = "0.10.20"
|
version = "0.10.21"
|
||||||
description = "A simple async ORM with fastapi in mind and pydantic validation."
|
description = "A simple async ORM with fastapi in mind and pydantic validation."
|
||||||
authors = ["Radosław Drążkiewicz <collerek@gmail.com>"]
|
authors = ["Radosław Drążkiewicz <collerek@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@ -43,12 +43,6 @@ class ModelExample(ormar.Model):
|
|||||||
raise ValueError("must contain a space")
|
raise ValueError("must contain a space")
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@pydantic.validator("str_field")
|
|
||||||
def validate_str_field2(cls, v):
|
|
||||||
if " " not in v:
|
|
||||||
raise ValueError("must contain a space")
|
|
||||||
return v
|
|
||||||
|
|
||||||
|
|
||||||
ModelExampleCreate = ModelExample.get_pydantic(exclude={"id"})
|
ModelExampleCreate = ModelExample.get_pydantic(exclude={"id"})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user