File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -310,7 +310,10 @@ def sideload(name)
310
310
# @return [Hash] The nested include hash
311
311
# @api private
312
312
def to_hash ( processed = [ ] )
313
- return { name => { } } if processed . include? ( self )
313
+ # Cut off at 5 recursions
314
+ if processed . select { |p | p == self } . length == 5
315
+ return { name => { } }
316
+ end
314
317
processed << self
315
318
316
319
result = { name => { } } . tap do |hash |
Original file line number Diff line number Diff line change @@ -295,6 +295,35 @@ def json
295
295
end
296
296
end
297
297
298
+ context 'sideloading the same "type", then adding another sideload' do
299
+ before do
300
+ Author . class_eval do
301
+ has_many :other_books , class_name : 'Book'
302
+ end
303
+
304
+ SerializableAuthor . class_eval do
305
+ has_many :other_books
306
+ end
307
+
308
+ Integration ::AuthorResource . class_eval do
309
+ has_many :other_books ,
310
+ scope : -> { Book . all } ,
311
+ foreign_key : :author_id ,
312
+ resource : Integration ::BookResource
313
+ end
314
+ end
315
+
316
+ it 'works' do
317
+ book2 . genre = Genre . create! name : 'Comedy'
318
+ book2 . save!
319
+ get :index , params : {
320
+ filter : { books : { id : book1 . id } , other_books : { id : book2 . id } } ,
321
+ include : 'books.genre,other_books.genre'
322
+ }
323
+ expect ( json_includes ( 'genres' ) . length ) . to eq ( 2 )
324
+ end
325
+ end
326
+
298
327
context 'sideloading polymorphic belongs_to' do
299
328
it 'allows extra fields for the sideloaded resource' do
300
329
get :index , params : {
You can’t perform that action at this time.
0 commit comments