Skip to content

Commit 6c0f6e0

Browse files
author
matmoncon
committed
docs: add documentation for register_models_from_directory method
1 parent e83c8e4 commit 6c0f6e0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/DatabaseClient.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ Models are a core feature of pyneo4j-ogm, and therefore you probably want to use
4747
await client.register_models([Developer, Coffee, Consumed])
4848
```
4949

50+
or by providing the path to a directory holding all your models. The `register_models_from_directory()` method will automatically discover all models in the directory and all of it's subdirectories and register them:
51+
52+
```python
53+
## Create a new client instance and connect ...
54+
55+
await client.register_models_from_directory("path/to/models")
56+
```
57+
5058
This is a crucial step, because if you don't register your models with the client, you won't be able to work with them in any way. Should you try to work with a model that has not been registered, you will get a `UnregisteredModel` exception. This exception also gets raised if a database model defines a relationship-property with other (unregistered) models as a target or relationship model and then runs a query with said relationship-property.
5159

5260
If you have defined any indexes or constraints on your models, they will be created automatically when registering them. You can prevent this behavior by passing `skip_constraints=True` or `skip_indexes=True` to the `connect()` method. If you do this, you will have to create the indexes and constraints yourself.

0 commit comments

Comments
 (0)