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
| Support `model` and `data` keys |:heavy_check_mark:|:heavy_check_mark:|
68
+
| Support `model` and `filter` keys |:x:|:heavy_check_mark:|
69
+
| Optional argument `add_to_session=False` in the `seed` method |:heavy_check_mark:|:x:|
71
70
72
71
## When to use HybridSeeder and 'filter' key field?
73
72
@@ -81,7 +80,7 @@ from db import session
81
80
data = {
82
81
"model": "models.Parent",
83
82
"data": {
84
-
"!child": {
83
+
"!child": {# '!' is the reference prefix
85
84
"model": "models.Child",
86
85
"filter": {
87
86
"age": 5
@@ -91,15 +90,17 @@ data = {
91
90
}
92
91
93
92
# When seeding instances that has 'filter' key, then use HybridSeeder, otherwise use Seeder.
94
-
seeder = HybridSeeder(session)
93
+
# ref_prefix can be changed according to your needs, defaults to '!'
94
+
seeder = HybridSeeder(session, ref_prefix='!')
95
95
seeder.seed(data)
96
96
97
97
session.commit() # or seeder.sesssion.commit()
98
98
```
99
99
100
100
## Relationships
101
101
102
-
In adding a relationship attribute, add prefix **!** to the key in order to identify it.
102
+
In adding a reference attribute, add prefix **!** or to the key in order to identify it.
103
+
If you want '@' as prefix, you can just specify it to what seeder you use by adding ref_prefix='@' in the argument when instantiating the seeder in order for the seeder to identify the referencing attributes
103
104
104
105
### Referencing relationship object or a foreign key
105
106
@@ -122,7 +123,7 @@ instance = [
122
123
'name': 'John Smith',
123
124
# foreign key attribute
124
125
'!company_id': {
125
-
'model': 'tests.models.Company',
126
+
'model': 'tests.models.Company',# models can be removed if it is a referencing attribute
126
127
'filter': {
127
128
'name': 'MyCompany'
128
129
}
@@ -132,7 +133,7 @@ instance = [
132
133
'name': 'Juan Dela Cruz',
133
134
# relationship attribute
134
135
'!company': {
135
-
'model': 'tests.models.Company',
136
+
'model': 'tests.models.Company',# models can be removed if it is a referencing attribute
0 commit comments