New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: replace "id" with model.IDField #604
Changes from 1 commit
e25179b
68bb93d
6965b00
91a5f8e
15e0292
c4b8e6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,7 +228,7 @@ func (c *Connection) Create(model interface{}, excludeColumns ...string) error { | |
} | ||
|
||
tn := m.TableName() | ||
cols := columns.ForStructWithAlias(m.Value, tn, m.As) | ||
cols := m.Columns() | ||
|
||
if tn == sm.TableName() { | ||
cols.Remove(excludeColumns...) | ||
|
@@ -350,8 +350,8 @@ func (c *Connection) Update(model interface{}, excludeColumns ...string) error { | |
} | ||
|
||
tn := m.TableName() | ||
cols := columns.ForStructWithAlias(model, tn, m.As) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This uses the outer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think this has had problems in the past where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it actually does not matter. It is not possible to pass a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know too little about reflection to judge this statement, so I would prefer reverting this to the original behavior just in case this breaks something somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, reverted |
||
cols.Remove("id", "created_at") | ||
cols := m.Columns() | ||
cols.Remove(m.IDField(), "created_at") | ||
|
||
if tn == sm.TableName() { | ||
cols.Remove(excludeColumns...) | ||
|
@@ -393,11 +393,11 @@ func (c *Connection) UpdateColumns(model interface{}, columnNames ...string) err | |
|
||
cols := columns.Columns{} | ||
if len(columnNames) > 0 && tn == sm.TableName() { | ||
cols = columns.NewColumnsWithAlias(tn, m.As) | ||
cols = columns.NewColumnsWithAlias(tn, m.As, sm.IDField()) | ||
cols.Add(columnNames...) | ||
|
||
} else { | ||
cols = columns.ForStructWithAlias(model, tn, m.As) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #604 (comment) |
||
cols = m.Columns() | ||
} | ||
cols.Remove("id", "created_at") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is missing two tests:
id
and the ID field can not be written but can be read.notid
and the ID field ca be written and read butnotid
can not be written.have a test where the PK is not
"id"
and you are not able to update that particular PKThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added cases but not everything is possible like you expect, see #556