File tree Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -246,14 +246,16 @@ function setRequestedIncludes (include) {
246246 if ( typeof include === 'string' ) {
247247 return include
248248 }
249+ if ( include instanceof Array ) {
250+ return include . map ( function ( inc ) {
251+ if ( typeof inc === 'string' ) {
252+ return inc
253+ }
249254
250- return include . map ( function ( inc ) {
251- if ( typeof inc === 'string' ) {
252- return inc
253- }
254-
255- if ( inc instanceof Object ) {
256- return inc . relation
257- }
258- } )
255+ if ( inc instanceof Object ) {
256+ return inc . relation
257+ }
258+ } )
259+ }
260+ return include
259261}
Original file line number Diff line number Diff line change @@ -127,6 +127,28 @@ describe('include option', function () {
127127 done ( )
128128 } )
129129 } )
130+ it ( 'should include comments' , function ( done ) {
131+ request ( app )
132+ . get ( '/posts/1?filter={"include":["comments"]}' )
133+ . end ( function ( err , res ) {
134+ expect ( err ) . to . equal ( null )
135+ expect ( res . body . included . length ) . equal ( 2 )
136+ expect ( res . body . included [ 0 ] . type ) . equal ( 'comments' )
137+ expect ( res . body . included [ 1 ] . type ) . equal ( 'comments' )
138+ done ( )
139+ } )
140+ } )
141+ it ( 'should include categories with empty attributes object' , function ( done ) {
142+ request ( app )
143+ . get ( '/posts/1?filter={"include":[{"relation":"category", "scope": {"fields": ["id"]}}]}' )
144+ . end ( function ( err , res ) {
145+ expect ( err ) . to . equal ( null )
146+ expect ( res . body . included . length ) . equal ( 3 )
147+ expect ( res . body . included [ 0 ] . type ) . equal ( 'categories' )
148+ expect ( res . body . included [ 0 ] . attributes ) . to . include ( { } )
149+ done ( )
150+ } )
151+ } )
130152 } )
131153 } )
132154} )
You can’t perform that action at this time.
0 commit comments