Commit Graph

180 Commits

Author SHA1 Message Date
Jinzhu 2b2f6e77af Add SchemaName to NamingStrategy 2021-08-11 16:20:29 +08:00
daheige 7a49629fd1 optimize Parse func for fieldValue.Interface 2021-07-28 19:00:34 +08:00
daheige a70254609d optimize setupValuerAndSetter func 2021-07-14 22:03:17 +08:00
Burak Demirpolat 0329b800b0
slightly better callback warning (#4495) 2021-07-13 16:38:44 +08:00
wangyuehong 80497f27a6
title foreign schema for many2many to avoid panic (#4496)
Co-authored-by: yuehong.wang <yuehong.wang@dena.jp>
2021-07-13 16:36:22 +08:00
heige 50e85e14d4
Code optimize (#4415)
* optimize gormSourceDir replace

* fmt.Errorf adjust and Optimize for-break

* strings trim

* feat: avoid using the same name field and if..else optimization adjustment

* optimization callbacks/create.go Create func if...else logic

* fix: callbacks/create.go Create func

* fix FileWithLineNum func and add gormSourceDir unit test

* remove debug print and utils_filenum_test.go
2021-06-10 10:21:28 +08:00
Brenda Wallace ac722c16f9
Small grammar fix in error message (#4406) 2021-05-24 10:23:34 +08:00
Paras Waykole 79f427d862
fixed has_many stopped working if field names are identical (#4387)
* fixed belongs_to & has_one reversed if field same

* hasmany same foreign key bug fixed and test added
2021-05-19 16:05:29 +08:00
Chen Quan a480bd8545
Update Optimize schema (#4364) 2021-05-10 09:51:50 +08:00
Jinzhu 6b7abc54a2 Fix tests 2021-05-06 13:06:31 +08:00
Jinzhu 2aca96d147 test ignore migration, close #4314, #4315 2021-05-05 08:26:48 +08:00
Paras Waykole 8f7f3ad315
fixed belongs_to & has_one reversed if field same (#4343) 2021-05-05 07:57:54 +08:00
Jinzhu 70e93e73d8 Check data type if copyable before change reference field's type 2021-04-30 16:35:55 +08:00
Sky34gl3 a855fe6402
Fixed naming longer than 64 characters (#4310)
Co-authored-by: Mickael MAUGER <mickael.mauger@almerys.com>
2021-04-22 13:11:19 +08:00
Chris Faulkner 15a46bc042
Fix some typos (#4294) 2021-04-19 21:03:39 +08:00
heige 74e7a9ca07
Optimize reflect value length and method (#4280)
* Respect ignore migration when add column (#4276)

continue https://github.com/go-gorm/gorm/pull/4028

* feat: Optimal value type acquisition for v (#4278)

* feat: optimize relect value length and value

* feat: optimize ConvertSliceOfMapToValuesForCreate method

Co-authored-by: yrong1997 <yrong1997@gmail.com>
2021-04-14 13:00:54 +08:00
heige 5555b010dc
feat: Optimal value type acquisition for v (#4278) 2021-04-13 09:41:30 +08:00
gavwu 8cfa9d98f0
Update field.go (#4228)
seems like the `if-else` branch do the same thing, so remove it
2021-04-02 09:56:38 +08:00
Jinzhu 220349ccf2 Fix omit associations, close #4161 2021-03-19 15:15:26 +08:00
Shubhendra Singh Chauhan 0348b1d3c1
chore: improve code quality (#4123)
* Combine multiple `append`s into a single call

* Clean up copied struct fields with type conversion

* Remove unnecessary use of slice
2021-03-08 10:46:43 +08:00
heige 02cb40531e
Optimize parse constraint (#4153)
* for Config.cacheStore store PreparedStmtDB key

* invalid db error and value and invalid value length error (#4151)

* support named params in Select API  (#4142)

* adds support for named arguments in select

* changes clause identifies and adds test

* optimize match english letters and midline

Co-authored-by: Ratan Phayade <ratanphayade@users.noreply.github.com>
2021-03-08 10:21:33 +08:00
Sivchari adf85d5b82
change the method of initializing slice (#4097)
* change the method of initializing slice and fixed the length to be specified as 0

* keep the association.go code in the var group

* keep the association.go code in the var group

* change to initializing in var group
2021-03-04 19:44:15 +08:00
Jinzhu 92a2389450 Fix create duplicated constraint, close #4090 2021-02-16 08:35:19 +08:00
Jinzhu 628a0ae707 Fix foreign key & reference with same name, close #4081 2021-02-15 09:10:51 +08:00
Joel Nordell 5744e29fbd
Replacer interface for more flexible NamingStrategy (#4042)
* Change NameReplacer to an interface, allowing custom Replacers.

* Add NoLowerCase option to skip the snake_casing of names.

* Move sync.Map from global variable into member of NamingStrategy.

This maintains backward compatibility by making the smap optional - the
NamingStrategy still works if it is nil. gorm.Open activates it by
calling Init() if the given Namer is a schema.NamingStrategy.

Also, this changes the key stored in the smap to be the original name,
instead of the replaced name.

* Refactor NamingStrategy tests to add more assertions about how and when Replacers get called.

* Remove the name cache from NamingStrategy.
2021-02-14 08:16:24 +08:00
yrong1997 2ba612e805
Add field tag to ignore migration (#4028)
* Add field tag to ignore migration

* Fix null value with space

* refactor migration tag
2021-02-09 16:03:02 +08:00
Jinzhu deff0594ee Save associations based on creatable/updatable permission, close #4056 2021-02-07 14:24:11 +08:00
heige e80853e7f5
optimization check for ParseCheckConstraints (#4063) 2021-02-07 10:12:13 +08:00
Jinzhu 8f37cb0195 Make has to be a const, close #4024 2021-02-01 10:42:13 +08:00
Jinzhu db0cc4d60b Fix too long foreign key/checker names, close #4026 2021-02-01 10:37:12 +08:00
Jinzhu 916338a9e1 Test migrate constraints, close #3986 2021-01-26 13:39:34 +08:00
Jinzhu 6095dbf939 Fix parse embedded relations, close #3964, #3965 2021-01-19 15:40:04 +08:00
Lisa Casner ce610a9560
title case schema name (#3940) 2021-01-13 13:05:05 +08:00
Jinzhu b864a5457a Allow foreign key following the default naming conventions, close #3928 2021-01-10 17:32:17 +08:00
Jinzhu 79864af9ff Allow customize auto increment increment 2020-12-30 11:16:40 +08:00
Jinzhu 065787c54e Compatible with with foreign key with ID suffix #3890 2020-12-28 18:20:55 +08:00
Jinzhu 8bf50a5592 Fix parse relations if only specfied References, close #3890 2020-12-28 17:58:12 +08:00
Jinzhu 6a0fca2195 Return error for invalid relations definition, close #3830 2020-12-06 18:07:16 +08:00
Jinzhu f655041908 Allow overwrite ignored field's permission, close #3829 2020-12-06 11:07:05 +08:00
Andy Bursavich 61d3a4d6ea
Fix schema initialization paths (#3825)
* Fix schema initialization paths

The initialized channel was only closed if the schema's cacheStore did not contain the embeddedCacheKey and there were no errors parsing relations.  If the key existed or an error occurred, it would not be closed. This could leave other goroutines waiting for synchronization that will never occur.

Additionally, the other code paths that wait for initialization to complete did not return the possible error.

* Unnest common schema initialization

This makes the common code path less deeply nested and the flow control easier to follow.
2020-12-04 11:28:38 +08:00
Jinzhu 0f77500917 Waiting for schema to be initialized, close #3790 2020-11-27 17:05:45 +08:00
Jinzhu 6950007d6a Fix failed to parse relations when using goroutinue, close #3790
commit ee0ec43e8dfa85c1c1a562c2d0d47776cf8abd92
Author: Jinzhu <wosmvp@gmail.com>
Date:   Fri Nov 27 14:31:57 2020 +0800

    Fix failed to parse relations when using goroutinue, close #3790

commit 590e73ff95
Author: rokeyzhao <rokeyzhao@tencent.com>
Date:   Thu Nov 26 20:27:55 2020 +0800

    test: no cache preload in goroutine
2020-11-27 14:32:20 +08:00
Jinzhu 66e8a72bf1 Support NameReplace for NamingStrategy, close #3779 2020-11-23 11:24:07 +08:00
alresvor a4c0c6b400
cache converted name (#3736)
BenchmarkToName-8     	  2322307	       521 ns/op	      88 B/op	       5 allocs/op
↓
BenchmarkToName-8     	19997366	        55.0 ns/op	       0 B/op	       0 allocs/op
2020-11-16 15:16:15 +08:00
Jinzhu 1e241aa645 Reduce GC alloc 2020-11-10 21:23:20 +08:00
Jinzhu cb591a7129 Fix panic when using FirstOrCreate with soft delete, close #3671 2020-10-23 18:40:05 +08:00
Jinzhu 5fee5b1b24 Add option tag support for index 2020-10-21 20:18:21 +08:00
Jinzhu 3d846957cd Compatible with tag notNull 2020-10-09 17:42:28 +08:00
Jinzhu a2faa41cbe Refactor NamingStrategy, close #3540 2020-09-28 10:55:27 +08:00
Jinzhu ba253982bf Fix Pluck with Time and Scanner 2020-09-24 20:08:24 +08:00