-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
log SQL for association query #686
Conversation
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.
Hi @schparky,
Thank you for your contribution.
I took a look at this PR along with the surrounding code and context, and I think replacing the low-level exec methods (c.TX.Exec()
and c.Store.Exec()
) with a logging-enabled higher-level exec method could be better than adding log()
in more places.
Could you please update the PR with the patch below? Just let me know if you don't have enough time. I will proceed with it as a part of the ongoing clean-up tasks.
diff --git a/executors.go b/executors.go
index 37b03b3..a290543 100644
--- a/executors.go
+++ b/executors.go
@@ -286,7 +286,7 @@ func (c *Connection) Create(model interface{}, excludeColumns ...string) error {
}
stm := after[index].AfterProcess()
if c.TX != nil && !stm.Empty() {
- _, err := c.TX.Exec(c.Dialect.TranslateSQL(stm.Statement), stm.Args...)
+ err := c.RawQuery(c.Dialect.TranslateSQL(stm.Statement), stm.Args...).Exec()
if err != nil {
return err
}
@@ -297,14 +297,7 @@ func (c *Connection) Create(model interface{}, excludeColumns ...string) error {
for index := range stms {
statements := stms[index].Statements()
for _, stm := range statements {
- if c.TX != nil {
- _, err := c.TX.Exec(c.Dialect.TranslateSQL(stm.Statement), stm.Args...)
- if err != nil {
- return err
- }
- continue
- }
- _, err = c.Store.Exec(c.Dialect.TranslateSQL(stm.Statement), stm.Args...)
+ err := c.RawQuery(c.Dialect.TranslateSQL(stm.Statement), stm.Args...).Exec()
if err != nil {
return err
}
The patch didn't work, possibly because I hadn't yet merged in the latest commits. I did it manually, so please check my work. |
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.
LGTM! Thanks!
As I described in Slack, the automatic CREATE for many-to-many relationship join table doesn't get logged. It looks like this may log more than this one query, but I'm not familiar enough with this code to know what other situations are addressed.