mirror of https://github.com/go-gorm/gorm.git
Export Unscoped Field for search
This commit is contained in:
parent
6e5d46bf37
commit
94adc3e1d8
|
@ -8,7 +8,7 @@ func BeforeDelete(scope *Scope) {
|
||||||
|
|
||||||
func Delete(scope *Scope) {
|
func Delete(scope *Scope) {
|
||||||
if !scope.HasError() {
|
if !scope.HasError() {
|
||||||
if !scope.Search.unscoped && scope.HasColumn("DeletedAt") {
|
if !scope.Search.Unscoped && scope.HasColumn("DeletedAt") {
|
||||||
scope.Raw(
|
scope.Raw(
|
||||||
fmt.Sprintf("UPDATE %v SET deleted_at=%v %v",
|
fmt.Sprintf("UPDATE %v SET deleted_at=%v %v",
|
||||||
scope.QuotedTableName(),
|
scope.QuotedTableName(),
|
||||||
|
|
2
main.go
2
main.go
|
@ -175,7 +175,7 @@ func (s *DB) Scopes(funcs ...func(*DB) *DB) *DB {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) Unscoped() *DB {
|
func (s *DB) Unscoped() *DB {
|
||||||
return s.clone().search.Unscoped().db
|
return s.clone().search.unscoped().db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) Attrs(attrs ...interface{}) *DB {
|
func (s *DB) Attrs(attrs ...interface{}) *DB {
|
||||||
|
|
|
@ -159,7 +159,7 @@ func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string)
|
||||||
func (scope *Scope) whereSql() (sql string) {
|
func (scope *Scope) whereSql() (sql string) {
|
||||||
var primaryConditions, andConditions, orConditions []string
|
var primaryConditions, andConditions, orConditions []string
|
||||||
|
|
||||||
if !scope.Search.unscoped && scope.Fields()["deleted_at"] != nil {
|
if !scope.Search.Unscoped && scope.Fields()["deleted_at"] != nil {
|
||||||
sql := fmt.Sprintf("(%v.deleted_at IS NULL OR %v.deleted_at <= '0001-01-02')", scope.QuotedTableName(), scope.QuotedTableName())
|
sql := fmt.Sprintf("(%v.deleted_at IS NULL OR %v.deleted_at <= '0001-01-02')", scope.QuotedTableName(), scope.QuotedTableName())
|
||||||
primaryConditions = append(primaryConditions, sql)
|
primaryConditions = append(primaryConditions, sql)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ type search struct {
|
||||||
limit string
|
limit string
|
||||||
group string
|
group string
|
||||||
tableName string
|
tableName string
|
||||||
unscoped bool
|
Unscoped bool
|
||||||
raw bool
|
raw bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func (s *search) clone() *search {
|
||||||
limit: s.limit,
|
limit: s.limit,
|
||||||
group: s.group,
|
group: s.group,
|
||||||
tableName: s.tableName,
|
tableName: s.tableName,
|
||||||
unscoped: s.unscoped,
|
Unscoped: s.Unscoped,
|
||||||
raw: s.raw,
|
raw: s.raw,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,8 @@ func (s *search) Raw(b bool) *search {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *search) Unscoped() *search {
|
func (s *search) unscoped() *search {
|
||||||
s.unscoped = true
|
s.Unscoped = true
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue