Skip to content

Commit 65e943a

Browse files
authored
fix apply with nil value (#8)
1 parent cb9dfb3 commit 65e943a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

changeset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *Changeset) Apply(doc *rel.Document, mut *rel.Mutation) {
8787
c.applyAssocMany(doc, field, mut, v)
8888
}
8989
default:
90-
if field != pField && v != nil && scannable(c.types[field]) {
90+
if field != pField && scannable(c.types[field]) {
9191
c.set(doc, mut, field, v)
9292
}
9393
}

changeset_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type User struct {
1919
Address Address
2020
CreatedAt time.Time
2121
UpdatedAt time.Time
22+
DeletedAt *time.Time
2223
}
2324

2425
type Transaction struct {
@@ -123,6 +124,7 @@ func TestChangesetApply(t *testing.T) {
123124
rel.Set("age", 20),
124125
rel.Set("created_at", now),
125126
rel.Set("updated_at", now),
127+
rel.Set("deleted_at", nil),
126128
)
127129
transaction1Mutation = rel.Apply(rel.NewDocument(&Transaction{}),
128130
rel.Set("item", "Sword"),
@@ -149,6 +151,8 @@ func TestChangesetApply(t *testing.T) {
149151
return ch
150152
})
151153

154+
PutChange(ch, "deleted_at", nil)
155+
152156
userMutation.SetAssoc("transactions", transaction1Mutation, transaction2Mutation)
153157
userMutation.SetAssoc("address", addressMutation)
154158

0 commit comments

Comments
 (0)