Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_type/nested_attributes/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def derive_class_name
end

def fetch_child(parent, id)
assigned = assigned_children(parent).detect { |r| r.id == id }
assigned = assigned_children(parent).detect { |r| r.id.to_s == id.to_s }
return assigned if assigned

if child = find_scope(parent).find_by_id(id)
Expand Down
13 changes: 13 additions & 0 deletions spec/active_type/nested_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ def should_assign_and_persist(assign, persist = assign)
should_assign_and_persist(["existing 1", "updated", "existing 3"])
end

it 'allows the id to be given as a string' do
subject.records = [
NestedAttributesSpec::Record.new(:persisted_string => "existing 1"),
NestedAttributesSpec::Record.new(:persisted_string => "existing 2"),
]
subject.records[0].id = 100
subject.records[1].id = 101

subject.records_attributes = { '1' => { 'id' => '101', 'persisted_string' => 'updated' } }

should_assign_and_persist(["existing 1", "updated"])
end

it 'does not update records matching a reject_if proc' do
extra_options.merge!(:reject_if => :bad)
subject.records = [
Expand Down