Skip to content

Commit

Permalink
Export Unscoped Field for search
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Mar 12, 2015
1 parent 6e5d46b commit 94adc3e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion callback_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion scope_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type search struct {
limit string
group string
tableName string
unscoped bool
Unscoped bool
raw bool
}

Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 94adc3e

Please sign in to comment.