From 94adc3e1d8b95e033975a19bec743a7b26cffb80 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 12 Mar 2015 15:01:59 +0800 Subject: [PATCH] Export Unscoped Field for search --- callback_delete.go | 2 +- main.go | 2 +- scope_private.go | 2 +- search.go | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/callback_delete.go b/callback_delete.go index eb1c202b..72236659 100644 --- a/callback_delete.go +++ b/callback_delete.go @@ -8,7 +8,7 @@ func BeforeDelete(scope *Scope) { func Delete(scope *Scope) { if !scope.HasError() { - if !scope.Search.unscoped && scope.HasColumn("DeletedAt") { + if !scope.Search.Unscoped && scope.HasColumn("DeletedAt") { scope.Raw( fmt.Sprintf("UPDATE %v SET deleted_at=%v %v", scope.QuotedTableName(), diff --git a/main.go b/main.go index e2ffe417..0f4af2ae 100644 --- a/main.go +++ b/main.go @@ -175,7 +175,7 @@ func (s *DB) Scopes(funcs ...func(*DB) *DB) *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 { diff --git a/scope_private.go b/scope_private.go index e3b97509..8d363225 100644 --- a/scope_private.go +++ b/scope_private.go @@ -159,7 +159,7 @@ func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string) func (scope *Scope) whereSql() (sql 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()) primaryConditions = append(primaryConditions, sql) } diff --git a/search.go b/search.go index 4bf0775e..2908bec1 100644 --- a/search.go +++ b/search.go @@ -18,7 +18,7 @@ type search struct { limit string group string tableName string - unscoped bool + Unscoped bool raw bool } @@ -38,7 +38,7 @@ func (s *search) clone() *search { limit: s.limit, group: s.group, tableName: s.tableName, - unscoped: s.unscoped, + Unscoped: s.Unscoped, raw: s.raw, } } @@ -120,8 +120,8 @@ func (s *search) Raw(b bool) *search { return s } -func (s *search) Unscoped() *search { - s.unscoped = true +func (s *search) unscoped() *search { + s.Unscoped = true return s }