@@ -178,8 +178,10 @@ describe('relationship utils', () => {
178
178
describe ( 'linkRelatedModels()' , function ( ) {
179
179
it ( 'belongsTo' , ( ) => {
180
180
setupBelongsTo ( )
181
+ const from = { model : Comment , id : 1 }
182
+ const to = { model : Post , data : 1 }
181
183
return Comment . create ( { } , { } )
182
- . then ( ( ) => linkRelatedModels ( 'post' , Comment , 1 , Post , 1 ) )
184
+ . then ( ( ) => linkRelatedModels ( 'post' , from , to ) )
183
185
. then ( ( ) => Comment . find ( { where : { postId : 1 } } ) )
184
186
. then ( comments => {
185
187
expect ( comments . length ) . to . equal ( 1 )
@@ -188,8 +190,10 @@ describe('relationship utils', () => {
188
190
} )
189
191
it ( 'hasMany' , ( ) => {
190
192
setupHasMany ( )
193
+ const from = { model : Post , id : 1 }
194
+ const to = { model : Comment , data : [ 2 , 3 , 4 ] }
191
195
return Comment . create ( [ { postId : 1 } , { postId : 1 } , { postId : 1 } , { } ] )
192
- . then ( ( ) => linkRelatedModels ( 'comments' , Post , 1 , Comment , [ 2 , 3 , 4 ] ) )
196
+ . then ( ( ) => linkRelatedModels ( 'comments' , from , to ) )
193
197
. then ( ( ) => Comment . find ( { where : { postId : 1 } } ) )
194
198
. then ( comments => {
195
199
expect ( comments . length ) . to . equal ( 3 )
@@ -200,6 +204,8 @@ describe('relationship utils', () => {
200
204
} )
201
205
it ( 'hasManyThrough' , ( ) => {
202
206
setupHasManyThrough ( )
207
+ const from = { model : Post , id : 1 }
208
+ const to = { model : Comment , data : [ 2 , 3 , 4 ] }
203
209
return Promise . all ( [
204
210
Post . create ( { } ) ,
205
211
Comment . create ( [ { } , { } , { } , { } ] ) ,
@@ -209,7 +215,7 @@ describe('relationship utils', () => {
209
215
{ postId : 1 , commentId : 3 }
210
216
] )
211
217
] )
212
- . then ( ( ) => linkRelatedModels ( 'comments' , Post , 1 , Comment , [ 2 , 3 , 4 ] ) )
218
+ . then ( ( ) => linkRelatedModels ( 'comments' , from , to ) )
213
219
. then ( ( ) => PostComment . find ( { where : { postId : 1 } } ) )
214
220
. then ( postComments => {
215
221
expect ( postComments . length ) . to . equal ( 3 )
@@ -220,8 +226,10 @@ describe('relationship utils', () => {
220
226
} )
221
227
it ( 'hasOne' , ( ) => {
222
228
setupHasOne ( )
229
+ const from = { model : Post , id : 1 }
230
+ const to = { model : Comment , data : 1 }
223
231
return Comment . create ( [ { } , { } ] )
224
- . then ( ( ) => linkRelatedModels ( 'comment' , Post , 1 , Comment , 1 ) )
232
+ . then ( ( ) => linkRelatedModels ( 'comment' , from , to ) )
225
233
. then ( ( ) => Comment . find ( { where : { postId : 1 } } ) )
226
234
. then ( comments => {
227
235
expect ( comments . length ) . to . equal ( 1 )
@@ -230,8 +238,10 @@ describe('relationship utils', () => {
230
238
} )
231
239
it ( 'hasOne null' , ( ) => {
232
240
setupHasOne ( )
241
+ const from = { model : Post , id : 1 }
242
+ const to = { model : Comment , data : null }
233
243
return Comment . create ( [ { postId : 1 } ] )
234
- . then ( ( ) => linkRelatedModels ( 'comment' , Post , 1 , Comment , null ) )
244
+ . then ( ( ) => linkRelatedModels ( 'comment' , from , to ) )
235
245
. then ( ( ) => Comment . find ( { where : { postId : null } } ) )
236
246
. then ( comments => {
237
247
expect ( comments . length ) . to . equal ( 1 )
0 commit comments