Skip to content

Support setting nullable fields#79

Open
cbelsole wants to merge 2 commits intomgutz:v1from
cbelsole:support_setting_nullable_fields
Open

Support setting nullable fields#79
cbelsole wants to merge 2 commits intomgutz:v1from
cbelsole:support_setting_nullable_fields

Conversation

@cbelsole
Copy link

@cbelsole cbelsole commented Apr 6, 2018

Issue

Added support for setting a nullable field. Previously this would fail because a nil pointer cannot be set:

# Nullable  *string         `db:"nullable"`

person3 := Person{Name: "Barack", Nullable: nil}
err = s.
	InsertInto("people").
	Columns("name", "nullable").
	Record(person3).
	Returning("id", "nullable").
	QueryStruct(&person3)

Fix

The fix (discovered by @pascallouisperez) is to skip fields that !v.CanSet().

Tests

I added tests for inserting selecting and updating nullable fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant