You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,6 +150,14 @@ Full documentation for this project is available at [https://yezyilomo.github.io
150
150
`python runtests.py`
151
151
152
152
153
+
## Writing & Deploying Docs
154
+
Run `pip3 install mkdocs-material` to install mkdocs-material
155
+
156
+
Run `mkdocs serve` to serve docs locally
157
+
158
+
Run `mkdocs gh-deploy --force` to deploy docs to gh-page
159
+
160
+
153
161
## Credits
154
162
* Implementation of this library is based on the idea behind [GraphQL](https://graphql.org/).
155
163
* My intention is to extend the capability of [drf-dynamic-fields](https://github.com/dbrgn/drf-dynamic-fields) library to support more functionalities like allowing to query nested fields both flat and iterable at any level and allow writing on nested fields while maintaining simplicity.
Copy file name to clipboardExpand all lines: docs/mutating_data.md
+69Lines changed: 69 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -447,6 +447,75 @@ This will remove all books associated with a course being updated.
447
447
<br>
448
448
449
449
450
+
### delete_on_null kwarg
451
+
When dealing with nested fields, there are scenarios where the previously assigned object or resource is no longer needed after the field is cleared (i.e. set to `null`). In such cases, passing `delete_on_null=True` kwarg enables automatic deletion of the previously assigned resource when the nested field is explicitly updated to `null`.
452
+
453
+
This keyword argument applies only to `ForeignKey` or `OneToOne` relationships.
454
+
The default value for `delete_on_null` kwarg is `False`.
455
+
456
+
Below is an example showing how to use `delete_on_null` kwarg.
457
+
```py
458
+
from rest_framework import serializers
459
+
from django_restql.fields import NestedField
460
+
from django_restql.serializers import NestedModelSerializer
Sending a mutation request to update this property by removing a location
494
+
495
+
```PUT/PATCH /api/property/1/```
496
+
497
+
Request Body
498
+
```js
499
+
{
500
+
"location":null
501
+
}
502
+
```
503
+
504
+
Response
505
+
```js
506
+
{
507
+
"id":1,
508
+
"price":30000,
509
+
"location":null
510
+
}
511
+
```
512
+
513
+
In this case, the property’s location is updated to null, and the previously assigned Location instance (with id: 5) is deleted from the database.
514
+
515
+
!!! note
516
+
`delete_on_null=True` can only be used when both `accept_pk=False` and `accept_pk_only=False`. This is because `accept_pk=True` or `accept_pk_only=True` typically implies that the nested object is not tightly coupled to the parent and may be referenced elsewhere. Automatically deleting it in such cases could lead to unintended side effects or broken references.
517
+
518
+
450
519
## Using DynamicFieldsMixin and NestedField together
451
520
You can use `DynamicFieldsMixin` and `NestedModelSerializer` together if you want your serializer to be writable(on nested fields) and support querying data, this is very common. Below is an example which shows how you can use `DynamicFieldsMixin` and `NestedField` together.
0 commit comments