Merge pull request #1 from go-gorm/master

update
This commit is contained in:
heige 2021-01-31 15:30:18 +08:00 committed by GitHub
commit 04e57577c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -17,7 +17,7 @@ The fantastic ORM library for Golang, aims to be developer friendly.
* Hooks (Before/After Create/Save/Update/Delete/Find) * Hooks (Before/After Create/Save/Update/Delete/Find)
* Eager loading with `Preload`, `Joins` * Eager loading with `Preload`, `Joins`
* Transactions, Nested Transactions, Save Point, RollbackTo to Saved Point * Transactions, Nested Transactions, Save Point, RollbackTo to Saved Point
* Context, Prepared Statment Mode, DryRun Mode * Context, Prepared Statement Mode, DryRun Mode
* Batch Insert, FindInBatches, Find To Map * Batch Insert, FindInBatches, Find To Map
* SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints, NamedArg, Search/Update/Create with SQL Expr * SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints, NamedArg, Search/Update/Create with SQL Expr
* Composite Primary Key * Composite Primary Key

View File

@ -385,7 +385,9 @@ func (association *Association) saveAssociation(clear bool, values ...interface{
for name, ok := range selectColumns { for name, ok := range selectColumns {
columnName := "" columnName := ""
if strings.HasPrefix(name, association.Relationship.Name) { if strings.HasPrefix(name, association.Relationship.Name) {
columnName = strings.TrimPrefix(name, association.Relationship.Name) if columnName = strings.TrimPrefix(name, association.Relationship.Name); columnName == ".*" {
columnName = name
}
} else if strings.HasPrefix(name, clause.Associations) { } else if strings.HasPrefix(name, clause.Associations) {
columnName = name columnName = name
} }
@ -404,7 +406,15 @@ func (association *Association) saveAssociation(clear bool, values ...interface{
selectedSaveColumns = append(selectedSaveColumns, ref.ForeignKey.Name) selectedSaveColumns = append(selectedSaveColumns, ref.ForeignKey.Name)
} }
} }
associationDB := association.DB.Session(&Session{}).Model(nil).Select(selectedSaveColumns).Session(&Session{})
associationDB := association.DB.Session(&Session{}).Model(nil)
if !association.DB.FullSaveAssociations {
associationDB.Select(selectedSaveColumns)
}
if len(omitColumns) > 0 {
associationDB.Omit(omitColumns...)
}
associationDB = associationDB.Session(&Session{})
switch reflectValue.Kind() { switch reflectValue.Kind() {
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array:

View File

@ -172,7 +172,7 @@ func Preload(db *gorm.DB) {
if name == clause.Associations { if name == clause.Associations {
for _, rel := range db.Statement.Schema.Relationships.Relations { for _, rel := range db.Statement.Schema.Relationships.Relations {
if rel.Schema == db.Statement.Schema { if rel.Schema == db.Statement.Schema {
preloadMap[rel.Name] = nil preloadMap[rel.Name] = map[string][]interface{}{}
} }
} }
} else { } else {

View File

@ -167,7 +167,6 @@ func (db *DB) Session(config *Session) *DB {
clone: 1, clone: 1,
} }
) )
if config.CreateBatchSize > 0 { if config.CreateBatchSize > 0 {
tx.Config.CreateBatchSize = config.CreateBatchSize tx.Config.CreateBatchSize = config.CreateBatchSize
} }