Merge pull request #309 from voice1/master
Updated common-parameters.md
This commit is contained in:
@ -101,7 +101,33 @@ Sample usage:
|
|||||||
|
|
||||||
!!!info
|
!!!info
|
||||||
`server_default` is passed straight to sqlalchemy table definition so you can read more in [server default][server default] sqlalchemy documentation
|
`server_default` is passed straight to sqlalchemy table definition so you can read more in [server default][server default] sqlalchemy documentation
|
||||||
|
|
||||||
|
## name
|
||||||
|
|
||||||
|
`name`: `str` = `None` -> defaults to None
|
||||||
|
|
||||||
|
Allows you to specify a column name alias to be used.
|
||||||
|
|
||||||
|
Useful for existing database structures that use a reserved keyword, or if you would like to use database name that is different from `ormar` field name.
|
||||||
|
|
||||||
|
Take for example the snippet below.
|
||||||
|
|
||||||
|
`from`, being a reserved word in python, will prevent you from creating a model with that column name.
|
||||||
|
|
||||||
|
Changing the model name to `from_` and adding the parameter `name='from'` will cause ormar to use `from` for the database column name.
|
||||||
|
|
||||||
|
```python
|
||||||
|
#... rest of Model cut for brevity
|
||||||
|
from_: str = ormar.String(max_length=15, name='from')
|
||||||
|
```
|
||||||
|
|
||||||
|
Similarly, you can change the foreign key column names in database, while keeping the desired relation name in ormar:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# ... rest of Model cut for brevity
|
||||||
|
album: Optional[Album] = ormar.ForeignKey(Album, name="album_id")
|
||||||
|
```
|
||||||
|
|
||||||
## index
|
## index
|
||||||
|
|
||||||
`index`: `bool` = `False` -> by default False,
|
`index`: `bool` = `False` -> by default False,
|
||||||
@ -147,4 +173,4 @@ Used in pydantic only.
|
|||||||
[relations]: ../relations/index.md
|
[relations]: ../relations/index.md
|
||||||
[queries]: ../queries/index.md
|
[queries]: ../queries/index.md
|
||||||
[pydantic]: https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
|
[pydantic]: https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
|
||||||
[server default]: https://docs.sqlalchemy.org/en/13/core/defaults.html#server-invoked-ddl-explicit-default-expressions
|
[server default]: https://docs.sqlalchemy.org/en/13/core/defaults.html#server-invoked-ddl-explicit-default-expressions
|
||||||
|
|||||||
Reference in New Issue
Block a user