Commit Graph

234 Commits

Author SHA1 Message Date
black-06 828e22b17f
feat: support embedded preload (#6137)
* feat: support embedded preload

* fix lint and test

* fix test...
2023-04-11 13:10:38 +08:00
Cr f0360dccbf
fix: embedded should be nil if not exists (#6219) 2023-04-11 10:13:25 +08:00
Truong Nguyen ed474152b1
Fix: Composite primary key with auto-increment value returns 0 after insert (#6127)
* Fix #4930 workaround for databases that support auto-increment in composite primary key.

* Add test for composite key with auto-increment.

* schema.go: use field.AutoIncrement instead of field.TagSettings["AUTOINCREMENT"], add test to check autoincrement:false

create_test.go: remove unused code: drop table CompositeKeyProduct

---------

Co-authored-by: Jinzhu <wosmvp@gmail.com>
2023-03-10 16:50:03 +08:00
Jinzhu 1643a36260 Fix possible concurrency problem for serializer 2023-03-10 16:39:57 +08:00
black-06 e66a059b82
fix: update panic if model is not ptr (#6037)
* fix: update panic if model is not ptr

* fix: update panic if model is not ptr

* fix: update panic if model is not ptr

* fix: raise an error if the value is not addressable

* fix: return
2023-02-18 09:20:29 +08:00
Michael Anstis 532e9cf4cc
Issue 6054: Unscoped not working with PreLoad on Joins (#6058)
* Issue 6054: Unscoped not working with PreLoad on Joins

* Formatting

---------

Co-authored-by: Michael Anstis <manstis@redhat.com>
2023-02-18 09:06:43 +08:00
Jinzhu d834dd60b7 Remove unnecessary code 2023-01-19 15:22:13 +08:00
Haibo baf1afa1fc
fix(schema): field is only unique when there is one unique index (#5974) 2023-01-11 14:05:39 +08:00
Jinzhu 3d91802b1d Fix unexpected alter table in auto migration, close #5942, #5943 2023-01-02 21:06:04 +08:00
Cr d9525d4da4
fix: skip append relation field to default db value (#5885)
* fix: relation field returning

* chore: gofumpt style
2022-12-01 20:26:59 +08:00
Jinzhu a0f4d3f7d2 Save as empty string for not nullable nil field serialized into json 2022-10-18 16:25:39 +08:00
Jinzhu ab5f80a8d8 Save as NULL for nil object serialized into json 2022-10-18 15:44:56 +08:00
Jinzhu 34fbe84580 Add TableName with NamingStrategy support, close #5726 2022-10-07 21:18:37 +08:00
jesse.tang 4b22a55a75
fix: primaryFields are overwritten (#5721) 2022-10-07 18:29:28 +08:00
Nguyen Huu Tuan 328f301982
add some test case which related the logic (#5477) 2022-09-22 18:35:21 +08:00
Jinzhu 3a72ba102e Allow shared foreign key for many2many jointable 2022-09-22 15:03:41 +08:00
hjwblog.com 6e03b97e26
fix: empty serilizer err #5524 (#5525)
* fix: empty serilizer err #5524

* feat: fix UnixSecondSerializer return nil

* feat: split type case

Co-authored-by: huanjiawei <huanjiawei@bytedance.com>
2022-07-27 13:59:47 +08:00
MJrocker 3c6eb14c92 Fixed some typos in the code comment 2022-07-27 10:22:49 +08:00
Cr 06e174e24d
fix: embedded default value (#5540) 2022-07-25 14:10:30 +08:00
Jinzhu 62fdc2bb3b Fix serializer with empty string 2022-07-11 11:51:05 +08:00
wws 3e6ab99043
fix:serializer contain field panic (#5461) 2022-06-25 16:32:47 +08:00
Cr 8d45714628
fix: reset null value in slice (#5417)
* fix: reset null value in slice

* fix: can not set field in-place in join
2022-06-14 13:48:50 +08:00
Cr 373bcf7aca
fix: many2many auto migrate (#5322)
* fix: many2many auto migrate

* fix: uuid ossp
2022-05-09 10:07:18 +08:00
Chiung-Ming Huang 0211ac91a2
index: add composite id (#5269)
* index: add composite id

* index: add test cases of composite id

* index: improve the comments for the test cases of composite id
2022-04-25 11:39:23 +08:00
aelmel 3643f856a3
check for pointer to pointer value (#5278)
* check for pointer to pointer value

* revert to Ptr

Co-authored-by: Alexei Melnic <alexei.melnic@meliora.xyz>
2022-04-24 09:10:36 +08:00
Jinzhu 74e07b049c Serializer unixtime support ptr of int 2022-04-11 22:07:56 +08:00
Jinzhu 41bef26f13 Remove shared sync pool for Scanner compatibility 2022-04-11 21:37:44 +08:00
Jinzhu 9144969c83 Allow to use tag to disable auto create/update time 2022-04-02 17:17:47 +08:00
Jinzhu f92e6747cb Handle field set value error 2022-03-23 17:24:25 +08:00
Jin 2d5cb997ed
style: fix linter check for NamingStrategy and onConflictOption (#5174) 2022-03-20 09:02:45 +08:00
Jinzhu 0097b39a77 Should ignore error when parsing default value for time, close #5176 2022-03-20 08:55:08 +08:00
ag9920 3c00980e01 fix: serializer use default valueOf in assignInterfacesToValue, close #5168
commit 58e1b2bffbc216f2862d040fb545a8a486e473b6
Author: Jinzhu <wosmvp@gmail.com>
Date:   Fri Mar 18 17:06:43 2022 +0800

    Refactor #5168

commit fb9233011d
Author: ag9920 <alexgong7@outlook.com>
Date:   Thu Mar 17 21:23:28 2022 +0800

    fix: serializer use default valueOf in assignInterfacesToValue
2022-03-18 17:12:17 +08:00
Jinzhu e6f7da0e0d Support Variable Relation 2022-03-18 14:30:30 +08:00
Jinzhu 63ac66b569 Support default tag for time.Time 2022-03-17 11:34:27 +08:00
labulakalia 61b4c31236
fix when index name is "type", parseFieldIndexes will set index TYPE is "TYPE" (#5155)
* fix index name is type, parseFieldIndexes will set index TYPE is "TYPE"

* check TYPE empty
2022-03-14 21:47:59 +08:00
Jinzhu 530b0a12b4 Add fast path for ValueOf, ReflectValueOf 2022-02-27 22:16:31 +08:00
jing1 3741f258d0
feat: support gob serialize (#5108) 2022-02-24 10:21:27 +08:00
Michael Nussbaum 45ef1da7e4
Fix naming longer then 64 chars with dots in table (#5045)
Ensures that foreign key relationships and indexes are given
syntactically valid names when their name length exceeds 64 characters
and they contained dot characters within the name. This is most often
relevant when a Postgres table name is fully qualified by including its schema
as part of its name
2022-02-24 10:10:20 +08:00
Jinzhu b1201fce4e Fix update with customized time type, close #5101 2022-02-23 17:48:26 +08:00
codingxh 664c5fb767
strings.replace -> strings.replaceAll (#5095)
Co-authored-by: huquan<xxhh_quan_g@163.com>
2022-02-20 19:55:04 +08:00
Jinzhu 39d84cba5f Add serializer support (#5078)
* Update context

* Update GormFieldValuer

* Add Serializer

* Add Serializer Interface

* Refactor gorm field

* Refactor setter, valuer

* Add sync.Pool

* Fix test

* Add pool manager

* Fix pool manager

* Add poolInitializer

* Add Serializer Scan support

* Add Serializer Value method

* Add serializer test

* Finish Serializer

* Fix JSONSerializer for postgres

* Fix JSONSerializer for sqlserver

* Test serializer tag

* Add unixtime serializer

* Update go.mod
2022-02-19 17:02:53 +08:00
li-jin-gou d22215129e
fix: replace empty table name result in panic (#5048)
* fix: replace empty name result in panic

* fix: replace empty table name result in panic
2022-02-08 17:06:10 +08:00
piyongcai a0d6ff1fea
time.Time, []byte type add alias support. (rebase master) (#4992)
* time.Time, []byte type add alias support

* reformat
2022-01-12 13:11:40 +08:00
kinggo b47cf57f5e
ci: add gofumpt check in reviewdog (#4973) 2022-01-06 15:02:53 +08:00
piyongcai 380cc64ff5
fix type alias AutoMigrate bug(Add Test Case) (#4888)
* fix type alias AutoMigrate bug. eg

```go
package main

type IDer interface{ GetID() int64 }

// ID will add some method to implement some interface eg: GetID
type ID int64
func (z ID) GetID() int64 { return int64(z) }

type Test struct {
	ID
	Code string `gorm:"size:50"`
	Name string `gorm:"size:50"`
}

func main() {
	db, err := gorm.Open(postgres.New(postgres.Config{
		DSN: `dsn`,
		PreferSimpleProtocol: false,
	}), &gorm.Config{
		Logger:                 logger.Default.LogMode(logger.Info),
		SkipDefaultTransaction: true,
	})
	if err != nil {
		log.Fatal(err)
	}

	if err = db.AutoMigrate(&Test{}); err != nil {
		// invalid embedded struct for Test's field ID, should be struct, but got main.ID
		log.Fatal(err)
	}
}
```

* fix type alias AutoMigrate bug. eg

```go
package main

type IDer interface{ GetID() int64 }

// ID will add some method to implement some interface eg: GetID
type ID int64
func (z ID) GetID() int64 { return int64(z) }

type Test struct {
	ID
	Code string `gorm:"size:50"`
	Name string `gorm:"size:50"`
}

func main() {
	db, err := gorm.Open(postgres.New(postgres.Config{
		DSN:                  `dsn`,
		PreferSimpleProtocol: false,
	}), &gorm.Config{
		Logger:                 logger.Default.LogMode(logger.Info),
		SkipDefaultTransaction: true,
	})
	if err != nil {
		log.Fatal(err)
	}

	if err = db.AutoMigrate(&Test{}); err != nil {
		// invalid embedded struct for Test's field ID, should be struct, but got main.ID
		log.Fatal(err)
	}
}
```

* Add typealis test.

* try to fix golangci-lint
2021-12-10 17:45:36 +08:00
Jinzhu 5daa413f41 Stabilize schema.FieldsWithDefaultDBValue's order, close #4643 2021-11-08 20:20:55 +08:00
Mayank Govilla d9d5c4dce0
Fix self-referential belongs to constraint (#4801)
* create tests for self-ref has one migration

* add relation equality check to avoid skipping self-referential schemas

* remove drop table error check
2021-11-08 09:47:29 +08:00
Jason Lee d3211908a0
Refactor ParseWithSchemaTable method and improve test. (#4789)
* Refactor ParseWithSchemaTable method and improve test.

* Fix schema.ParseWithSchemaTable method for only use schemaTable in migrator and improve test.

* Rename `schemaTable` to `specialTableName` for clearly argument.
2021-10-25 11:26:44 +08:00
Wendell Sun a3bd9c3ea2 fix: automigrate error caused by indexes while using dynamic table name 2021-10-19 09:59:57 +08:00
kinggo ec58e3319f
fixed:panic when create value from nil struct pointer. (#4771)
* fixed:create nil pointer

* fixed:panic when create value from nil struct pointer.
2021-10-12 21:19:08 +08:00