Skip to content
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

Models with composite keys cannot be successfully removed using Delete(...) #4879

Open
jimlambrt opened this issue Nov 27, 2021 · 5 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@jimlambrt
Copy link
Contributor

jimlambrt commented Nov 27, 2021

GORM Playground Link

go-gorm/playground#405

Description

I think, Gorm should generate valid sql and be able to delete resources with composite primary keys.

Thanks for all your amazing work on Gorm!

If I have time, I may do a bit of digging on the issue and see about opening a PR to fix it. No promises about the PR but I'll see if I can mange it next week.

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Nov 27, 2021
@jinzhu
Copy link
Member

jinzhu commented Nov 29, 2021

also refer #3585

@jinzhu
Copy link
Member

jinzhu commented Nov 29, 2021

might need to replace the where clause for sqlite.

@awmcclain
Copy link

This is also biting us for testing.

@clausMeko
Copy link

Is this still an issue? If so maybe only in SQLite? I am using postgres where it works as expected.
So maybe update the Issue to include ... on sqlite?

@rohfle
Copy link

rohfle commented Sep 14, 2022

I ran the test from the above playground link and it passed for sqlite.
Heres the go.mod diff after running the test locally

diff --git a/go.mod b/go.mod
index 28f863c..f57a261 100644
--- a/go.mod
    b/go.mod
@@ -3,16  3,19 @@ module gorm.io/playground
 go 1.16
 
 require (
        github.com/denisenkom/go-mssqldb v0.12.2 // indirect
        github.com/go-kit/kit v0.10.0 // indirect
        github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
        github.com/hashicorp/go-secure-stdlib/base62 v0.1.2 // indirect
-       github.com/jackc/pgx/v4 v4.14.0 // indirect
-       golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
        github.com/jackc/pgx/v4 v4.17.2 // indirect
        github.com/mattn/go-sqlite3 v1.14.15 // indirect
        golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
        golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
-       gorm.io/driver/mysql v1.2.0
-       gorm.io/driver/postgres v1.2.2
-       gorm.io/driver/sqlite v1.2.6
-       gorm.io/driver/sqlserver v1.2.1
-       gorm.io/gorm v1.22.3
        gorm.io/driver/mysql v1.3.6
        gorm.io/driver/postgres v1.3.9
        gorm.io/driver/sqlite v1.3.6
        gorm.io/driver/sqlserver v1.3.2
        gorm.io/gorm v1.23.8
 )
 
 replace gorm.io/gorm => ./gorm

test log

testing sqlite...
2022/09/15 05:45:55 testing sqlite3...

2022/09/15 05:45:56 ~/go/pkg/mod/gorm.io/driver/[email protected]/migrator.go:45 SLOW SQL >= 200ms
[1397.456ms] [rows:0] DROP TABLE IF EXISTS `companies`
=== RUN   TestGORM

2022/09/15 05:45:56 ~/playground/main_test.go:16
[4.526ms] [rows:1] INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`,`birthday`,`company_id`,`manager_id`,`active`) VALUES ("2022-09-15 05:45:56.896","2022-09-15 05:45:56.896",NULL,"jinzhu",0,NULL,NULL,NULL,false) RETURNING `id`

2022/09/15 05:45:56 ~/playground/main_test.go:19
[0.634ms] [rows:1] SELECT * FROM `users` WHERE `users`.`id` = 1 AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT 1

2022/09/15 05:45:56 ~/playground/main_test.go:35
[3.510ms] [rows:1] INSERT INTO `model_with_composite_keys` (`key_one`,`key_two`) VALUES ("fBvutjiGPO","qxJJEIR0o2")

2022/09/15 05:45:56 ~/playground/main_test.go:38
[3.891ms] [rows:1] DELETE FROM `model_with_composite_keys` WHERE (`model_with_composite_keys`.`key_one`,`model_with_composite_keys`.`key_two`) IN (("fBvutjiGPO","qxJJEIR0o2"))
--- PASS: TestGORM (0.01s)
PASS
ok  	gorm.io/playground	1.681s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

5 participants