commit
						da8c2409ab
					
				@ -208,7 +208,7 @@ func sortProcessors(cps []*CallbackProcessor) []*func(scope *Scope) {
 | 
				
			|||||||
	return sortedFuncs
 | 
						return sortedFuncs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// reorder all registered processors, and reset CURD callbacks
 | 
					// reorder all registered processors, and reset CRUD callbacks
 | 
				
			||||||
func (c *Callback) reorder() {
 | 
					func (c *Callback) reorder() {
 | 
				
			||||||
	var creates, updates, deletes, queries, rowQueries []*CallbackProcessor
 | 
						var creates, updates, deletes, queries, rowQueries []*CallbackProcessor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								main.go
									
									
									
									
									
								
							@ -161,7 +161,7 @@ func (s *DB) SingularTable(enable bool) {
 | 
				
			|||||||
	s.parent.singularTable = enable
 | 
						s.parent.singularTable = enable
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Where return a new relation, filter records with given conditions, accepts `map`, `struct` or `string` as conditions, refer http://jinzhu.github.io/gorm/curd.html#query
 | 
					// Where return a new relation, filter records with given conditions, accepts `map`, `struct` or `string` as conditions, refer http://jinzhu.github.io/gorm/crud.html#query
 | 
				
			||||||
func (s *DB) Where(query interface{}, args ...interface{}) *DB {
 | 
					func (s *DB) Where(query interface{}, args ...interface{}) *DB {
 | 
				
			||||||
	return s.clone().search.Where(query, args...).db
 | 
						return s.clone().search.Where(query, args...).db
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -233,7 +233,7 @@ func (s *DB) Joins(query string, args ...interface{}) *DB {
 | 
				
			|||||||
//     }
 | 
					//     }
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//     db.Scopes(AmountGreaterThan1000, OrderStatus([]string{"paid", "shipped"})).Find(&orders)
 | 
					//     db.Scopes(AmountGreaterThan1000, OrderStatus([]string{"paid", "shipped"})).Find(&orders)
 | 
				
			||||||
// Refer https://jinzhu.github.io/gorm/curd.html#scopes
 | 
					// Refer https://jinzhu.github.io/gorm/crud.html#scopes
 | 
				
			||||||
func (s *DB) Scopes(funcs ...func(*DB) *DB) *DB {
 | 
					func (s *DB) Scopes(funcs ...func(*DB) *DB) *DB {
 | 
				
			||||||
	for _, f := range funcs {
 | 
						for _, f := range funcs {
 | 
				
			||||||
		s = f(s)
 | 
							s = f(s)
 | 
				
			||||||
@ -241,17 +241,17 @@ func (s *DB) Scopes(funcs ...func(*DB) *DB) *DB {
 | 
				
			|||||||
	return s
 | 
						return s
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Unscoped return all record including deleted record, refer Soft Delete https://jinzhu.github.io/gorm/curd.html#soft-delete
 | 
					// Unscoped return all record including deleted record, refer Soft Delete https://jinzhu.github.io/gorm/crud.html#soft-delete
 | 
				
			||||||
func (s *DB) Unscoped() *DB {
 | 
					func (s *DB) Unscoped() *DB {
 | 
				
			||||||
	return s.clone().search.unscoped().db
 | 
						return s.clone().search.unscoped().db
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Attrs initialize struct with argument if record not found with `FirstOrInit` https://jinzhu.github.io/gorm/curd.html#firstorinit or `FirstOrCreate` https://jinzhu.github.io/gorm/curd.html#firstorcreate
 | 
					// Attrs initialize struct with argument if record not found with `FirstOrInit` https://jinzhu.github.io/gorm/crud.html#firstorinit or `FirstOrCreate` https://jinzhu.github.io/gorm/crud.html#firstorcreate
 | 
				
			||||||
func (s *DB) Attrs(attrs ...interface{}) *DB {
 | 
					func (s *DB) Attrs(attrs ...interface{}) *DB {
 | 
				
			||||||
	return s.clone().search.Attrs(attrs...).db
 | 
						return s.clone().search.Attrs(attrs...).db
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Assign assign result with argument regardless it is found or not with `FirstOrInit` https://jinzhu.github.io/gorm/curd.html#firstorinit or `FirstOrCreate` https://jinzhu.github.io/gorm/curd.html#firstorcreate
 | 
					// Assign assign result with argument regardless it is found or not with `FirstOrInit` https://jinzhu.github.io/gorm/crud.html#firstorinit or `FirstOrCreate` https://jinzhu.github.io/gorm/crud.html#firstorcreate
 | 
				
			||||||
func (s *DB) Assign(attrs ...interface{}) *DB {
 | 
					func (s *DB) Assign(attrs ...interface{}) *DB {
 | 
				
			||||||
	return s.clone().search.Assign(attrs...).db
 | 
						return s.clone().search.Assign(attrs...).db
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -325,7 +325,7 @@ func (s *DB) Related(value interface{}, foreignKeys ...string) *DB {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FirstOrInit find first matched record or initialize a new one with given conditions (only works with struct, map conditions)
 | 
					// FirstOrInit find first matched record or initialize a new one with given conditions (only works with struct, map conditions)
 | 
				
			||||||
// https://jinzhu.github.io/gorm/curd.html#firstorinit
 | 
					// https://jinzhu.github.io/gorm/crud.html#firstorinit
 | 
				
			||||||
func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB {
 | 
					func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB {
 | 
				
			||||||
	c := s.clone()
 | 
						c := s.clone()
 | 
				
			||||||
	if result := c.First(out, where...); result.Error != nil {
 | 
						if result := c.First(out, where...); result.Error != nil {
 | 
				
			||||||
@ -340,7 +340,7 @@ func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FirstOrCreate find first matched record or create a new one with given conditions (only works with struct, map conditions)
 | 
					// FirstOrCreate find first matched record or create a new one with given conditions (only works with struct, map conditions)
 | 
				
			||||||
// https://jinzhu.github.io/gorm/curd.html#firstorcreate
 | 
					// https://jinzhu.github.io/gorm/crud.html#firstorcreate
 | 
				
			||||||
func (s *DB) FirstOrCreate(out interface{}, where ...interface{}) *DB {
 | 
					func (s *DB) FirstOrCreate(out interface{}, where ...interface{}) *DB {
 | 
				
			||||||
	c := s.clone()
 | 
						c := s.clone()
 | 
				
			||||||
	if result := s.First(out, where...); result.Error != nil {
 | 
						if result := s.First(out, where...); result.Error != nil {
 | 
				
			||||||
@ -354,12 +354,12 @@ func (s *DB) FirstOrCreate(out interface{}, where ...interface{}) *DB {
 | 
				
			|||||||
	return c
 | 
						return c
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Update update attributes with callbacks, refer: https://jinzhu.github.io/gorm/curd.html#update
 | 
					// Update update attributes with callbacks, refer: https://jinzhu.github.io/gorm/crud.html#update
 | 
				
			||||||
func (s *DB) Update(attrs ...interface{}) *DB {
 | 
					func (s *DB) Update(attrs ...interface{}) *DB {
 | 
				
			||||||
	return s.Updates(toSearchableMap(attrs...), true)
 | 
						return s.Updates(toSearchableMap(attrs...), true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Updates update attributes with callbacks, refer: https://jinzhu.github.io/gorm/curd.html#update
 | 
					// Updates update attributes with callbacks, refer: https://jinzhu.github.io/gorm/crud.html#update
 | 
				
			||||||
func (s *DB) Updates(values interface{}, ignoreProtectedAttrs ...bool) *DB {
 | 
					func (s *DB) Updates(values interface{}, ignoreProtectedAttrs ...bool) *DB {
 | 
				
			||||||
	return s.clone().NewScope(s.Value).
 | 
						return s.clone().NewScope(s.Value).
 | 
				
			||||||
		Set("gorm:ignore_protected_attrs", len(ignoreProtectedAttrs) > 0).
 | 
							Set("gorm:ignore_protected_attrs", len(ignoreProtectedAttrs) > 0).
 | 
				
			||||||
@ -367,12 +367,12 @@ func (s *DB) Updates(values interface{}, ignoreProtectedAttrs ...bool) *DB {
 | 
				
			|||||||
		callCallbacks(s.parent.callbacks.updates).db
 | 
							callCallbacks(s.parent.callbacks.updates).db
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateColumn update attributes without callbacks, refer: https://jinzhu.github.io/gorm/curd.html#update
 | 
					// UpdateColumn update attributes without callbacks, refer: https://jinzhu.github.io/gorm/crud.html#update
 | 
				
			||||||
func (s *DB) UpdateColumn(attrs ...interface{}) *DB {
 | 
					func (s *DB) UpdateColumn(attrs ...interface{}) *DB {
 | 
				
			||||||
	return s.UpdateColumns(toSearchableMap(attrs...))
 | 
						return s.UpdateColumns(toSearchableMap(attrs...))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateColumns update attributes without callbacks, refer: https://jinzhu.github.io/gorm/curd.html#update
 | 
					// UpdateColumns update attributes without callbacks, refer: https://jinzhu.github.io/gorm/crud.html#update
 | 
				
			||||||
func (s *DB) UpdateColumns(values interface{}) *DB {
 | 
					func (s *DB) UpdateColumns(values interface{}) *DB {
 | 
				
			||||||
	return s.clone().NewScope(s.Value).
 | 
						return s.clone().NewScope(s.Value).
 | 
				
			||||||
		Set("gorm:update_column", true).
 | 
							Set("gorm:update_column", true).
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user