@@ -54,4 +54,32 @@ describe('DSSqlAdapter#find', function () {
54
54
assert . equal ( err . message , 'Not Found!' ) ;
55
55
}
56
56
} ) ;
57
+
58
+ it ( 'should load belongsTo relations' , function * ( ) {
59
+ var profile = yield adapter . create ( Profile , { email :
'[email protected] ' } ) ;
60
+ var user = yield adapter . create ( User , { name : 'John' , profileId : profile . id } ) ;
61
+ var post = yield adapter . create ( Post , { content : 'foo' , userId : user . id } ) ;
62
+ var comment = yield adapter . create ( Comment , { content : 'test2' , postId : post . id , userId : post . userId } ) ;
63
+
64
+ var comment = yield adapter . find ( Comment , comment . id , { 'with' : [ 'user' , 'user.profile' , 'post' , 'post.user' ] } ) ;
65
+ assert . isDefined ( comment ) ;
66
+ assert . isDefined ( comment . post ) ;
67
+ assert . isDefined ( comment . post . user ) ;
68
+ assert . isDefined ( comment . user ) ;
69
+ assert . isDefined ( comment . user . profile ) ;
70
+ } ) ;
71
+
72
+ it ( 'should load hasMany and belongsTo relations' , function * ( ) {
73
+ var profile = yield adapter . create ( Profile , { email :
'[email protected] ' } ) ;
74
+ var user = yield adapter . create ( User , { name : 'John' , profileId : profile . id } ) ;
75
+ var post = yield adapter . create ( Post , { content : 'foo' , userId : user . id } ) ;
76
+ var comment = yield adapter . create ( Comment , { content : 'test2' , postId : post . id , userId : post . userId } ) ;
77
+
78
+ var foundPost = yield adapter . find ( Post , post . id , { 'with' : [ 'user' , 'comment' , 'comment.user' , 'comment.user.profile' ] } ) ;
79
+ assert . isDefined ( foundPost . comments ) ;
80
+ assert . isDefined ( foundPost . comments [ 0 ] . user ) ;
81
+ assert . isDefined ( foundPost . comments [ 0 ] . user . profile ) ;
82
+ assert . isDefined ( foundPost . user ) ;
83
+ } ) ;
84
+
57
85
} ) ;
0 commit comments