File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -31,11 +31,12 @@ let Author = Person.extend({
31
31
32
32
nilly : attr ( ) ,
33
33
34
- multiWords : hasMany ( 'multi_words' ) ,
35
- books : hasMany ( ) ,
36
- tags : hasMany ( ) ,
37
- genre : belongsTo ( 'genres' ) ,
38
- bio : hasOne ( 'bios' )
34
+ multiWords : hasMany ( 'multi_words' ) ,
35
+ specialBooks : hasMany ( 'books' ) ,
36
+ books : hasMany ( ) ,
37
+ tags : hasMany ( ) ,
38
+ genre : belongsTo ( 'genres' ) ,
39
+ bio : hasOne ( 'bios' )
39
40
} ) ;
40
41
41
42
class Book extends ApplicationRecord {
Original file line number Diff line number Diff line change @@ -203,6 +203,12 @@ describe('Model', function() {
203
203
type : 'books'
204
204
} ]
205
205
} ,
206
+ special_books : {
207
+ data : [ {
208
+ id : '3' ,
209
+ type : 'books'
210
+ } ]
211
+ } ,
206
212
bio : {
207
213
data : {
208
214
id : '1' ,
@@ -223,8 +229,8 @@ describe('Model', function() {
223
229
} ,
224
230
relationships : {
225
231
author : {
226
- data : {
227
- id : '2' ,
232
+ data : {
233
+ id : '2' ,
228
234
type : 'authors'
229
235
} ,
230
236
}
@@ -245,6 +251,13 @@ describe('Model', function() {
245
251
}
246
252
}
247
253
} ,
254
+ {
255
+ type : 'books' ,
256
+ id : '3' ,
257
+ attributes : {
258
+ title : "Peanut Butter & Cupcake"
259
+ }
260
+ } ,
248
261
{
249
262
type : 'genres' ,
250
263
id : '1' ,
@@ -332,6 +345,14 @@ describe('Model', function() {
332
345
expect ( book . title ) . to . eq ( "Where's My Butt?" ) ;
333
346
} ) ;
334
347
348
+ it ( 'assigns hasMany relationships with same jsonapiType correctly' , function ( ) {
349
+ let instance = Model . fromJsonapi ( doc . data , doc ) ;
350
+ expect ( instance . specialBooks . length ) . to . eq ( 1 ) ;
351
+ let book = instance . specialBooks [ 0 ] ;
352
+ expect ( book ) . to . be . instanceof ( Book ) ;
353
+ expect ( book . title ) . to . eq ( "Peanut Butter & Cupcake" ) ;
354
+ } ) ;
355
+
335
356
it ( 'assigns belongsTo relationships correctly' , function ( ) {
336
357
let instance = Model . fromJsonapi ( doc . data , doc ) ;
337
358
let genre = instance . genre ;
You can’t perform that action at this time.
0 commit comments