Skip to content

Commit

Permalink
Fix for nil assocations in has_snapshot_children on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Aug 27, 2021
1 parent b2f4a87 commit 0715279
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CHANGELOG

- **UNRELEASED**
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.1...master)
* Nothing yet
* [](https://github.com/westonganger/active_snapshot/commit/) - Fix bug on restore for in `has_snapshot_children` method with nil association values

- **v0.2.1** - August 19, 2021
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.0...v0.2.1)
Expand Down
3 changes: 2 additions & 1 deletion lib/active_snapshot/models/concerns/snapshots_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def children_to_snapshot
snapshot_children[assoc_name] = {}

if opts.nil?
next # skip, nil is allowed value in case has_one/belongs_to is nil, etc.
### nil is allowed value in case has_one/belongs_to is nil, etc.
snapshot_children[assoc_name][:records] = []

elsif opts.is_a?(ActiveRecord::Base)
### Support belongs_to / has_one
Expand Down
1 change: 1 addition & 0 deletions test/dummy_app/app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Post < ActiveRecord::Base
{
comments: instance.comments,
notes: instance.notes,
nil_assoc: nil,
}
end
end

0 comments on commit 0715279

Please sign in to comment.