From 216e2114df22989e29e7697a86ce994a299bbe06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Szcz=C4=99=C5=9Bniak?= Date: Fri, 9 Mar 2018 10:02:14 +0100 Subject: [PATCH] Deletion populator and multiple new records I found out that using the default example for deletion Populator does not allow to have multiple new items added to collection. In this case all new fragments do not have `id`. So find matcher will return the wrong item since `song.id.to_s == fragment["id"].to_s` (nil == nil) will always be true from 2nd run. I suggest we additonally check for id presence. --- gems/reform/populator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gems/reform/populator.md b/gems/reform/populator.md index 6b103446..c4714595 100644 --- a/gems/reform/populator.md +++ b/gems/reform/populator.md @@ -269,7 +269,7 @@ You can implement your own deletion. collection :songs, populator: ->(fragment:, **) { # find out if incoming song is already added. - item = songs.find { |song| song.id.to_s == fragment["id"].to_s } + item = songs.find { |song| song.id.present? && song.id.to_s == fragment["id"].to_s } if fragment["delete"] == "1" songs.delete(item)