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
| Optional argument `add_to_session=False` in the `seed` method |✔️ | ❌|
70
71
71
72
## When to use HybridSeeder and 'filter' key field?
72
73
73
-
Assuming that `Child(age=5)` exists in the database or session, then we should use *filter* instead of *data*, the
74
-
values of *filter* will query from the database or session, and assign it to the `Parent.child`
74
+
Assuming that `Child(age=5)` exists in the database or session, then we should use `filter` instead of `data`, the
75
+
values of `filter` will query from the database or session, and assign it to the `Parent.child`
75
76
76
77
```python
77
78
from sqlalchemyseed import HybridSeeder
@@ -89,8 +90,10 @@ data = {
89
90
}
90
91
}
91
92
92
-
# When seeding instances that has 'filter' key, then use HybridSeeder, otherwise use Seeder.
93
-
# ref_prefix can be changed according to your needs, defaults to '!'
93
+
# When seeding instances that has 'filter' key,
94
+
# then use HybridSeeder, otherwise use Seeder.
95
+
# ref_prefix can be changed according to your needs,
96
+
# defaults to '!'
94
97
seeder = HybridSeeder(session, ref_prefix='!')
95
98
seeder.seed(data)
96
99
@@ -99,14 +102,21 @@ session.commit() # or seeder.sesssion.commit()
99
102
100
103
## Relationships
101
104
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
105
+
In adding a reference attribute, add prefix to the key in order to identify it. Default prefix is `!`.
106
+
107
+
Reference attribute can either be foreign key or relationship attribute. See examples below.
108
+
109
+
### Customizing prefix
110
+
111
+
If you want '@' as prefix, you can just specify it to what seeder you use by adding ref_prefix='@' in the argument like this `seeder = Seeder(session, ref_prefix='@')`, in order for the seeder to identify the referencing attributes
104
112
105
113
### Referencing relationship object or a foreign key
106
114
107
115
If your class don't have a relationship attribute but instead a foreign key attribute you can use it the same as how you
108
116
did it on a relationship attribute
109
117
118
+
**Note**: `model` can be removed if it is a reference attribute.
119
+
110
120
```python
111
121
from sqlalchemyseed import HybridSeeder
112
122
from db import session
@@ -150,7 +160,7 @@ seeder.session.commit() # or session.commit()
150
160
### No Relationship
151
161
152
162
```json5
153
-
//test_data.json
163
+
//data.json
154
164
[
155
165
{
156
166
"model": "models.Person",
@@ -196,7 +206,7 @@ seeder.session.commit() # or session.commit()
196
206
}
197
207
},
198
208
//or this, if you want to add relationship that exists
199
-
//in your database use 'filter' instead of 'obj'
209
+
//in your database use 'filter' instead of 'data'
200
210
{
201
211
"model": "models.Person",
202
212
"data": {
@@ -306,7 +316,9 @@ data:
306
316
307
317
### CSV
308
318
309
-
data.csv
319
+
In line one, name and age, are attributes of a model that will be specified when loading the file.
0 commit comments