-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Update from #6579
Update from #6579
Conversation
b72b004
to
547a294
Compare
@@ -882,3 +882,52 @@ func TestSaveWithHooks(t *testing.T) { | |||
t.Errorf(`token content should be "token2_encrypted", but got: "%s"`, o2.Token.Content) | |||
} | |||
} | |||
|
|||
// only postgres, sqlserver, sqlite support update from | |||
func TestUpdateFrom(t *testing.T) { |
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.
the test failed when running all test cases
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.
@jinzhu It seems that the problem is not these tests, but the new versions of the drivers that were taged and are used to run the tests in the ci (in master the tests passed because the ci was run before the new tags were created). For the postgree driver the v1.5.3 tag was created but the tests do not pass using this version (they do not pass because of the changes in the commit go-gorm/postgres@7ba909e specifically). In the same way, in the mysql driver the v1.5.2 tag was created but the tests don't pass since the changes of the commit go-gorm/mysql@2a61ba0. In my fork (https://github.com/ditrit/gorm) you can see the master tests do not pass with the new driver tags
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.
@FrancoLiberali The test failure has nothing to do with this PR. You seem to have investigated the cause of the failure. Are you interested in creating other PRs to fix it?
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.
@a631807682 To be honest, I only ran the tests on the different driver's commits to find out from which one the tests don't work, but I don't know what is the purpose of the changes in those commits to fix the generated problems
547a294
to
c04c6cf
Compare
merged by f0af94c |
Is it possible you can write some sample code how to translate this SQL sentence into GORM? |
@haihanj As you can see in the added tests, the way is to add the From clause manually:
I hope this is helpful |
What did this pull request do?
To demonstrate that the changes in the following pull requests make sense:
go-gorm/sqlserver#115, go-gorm/sqlite#166, go-gorm/postgres#213
Add a test to show that "update from" is possible without making changes to the code (by adding the clause.From manually).
This test will not work until the new versions of the dialectors are used. I don't know what flow you follow to make this update.
User Case Description
Add an EXISTS condition to an UPDATE in a simpler way:
UPDATE table_name_1
SET attribute = "value"
FROM table_name_2
WHERE table_name_2.table_1_id = table_name_1.id
This is equivalent to:
UPDATE table_name_1
SET attribute = "value"
WHERE EXISTS (select 1 FROM table_name_2 WHERE table_name_2.table_1_id = table_name_1.id)