forked from mirror/gorm
make first, last works with plugin system
This commit is contained in:
parent
db68e7a8fe
commit
549d7a8af2
9
main.go
9
main.go
|
@ -110,12 +110,17 @@ func (s *DB) Unscoped() *DB {
|
|||
}
|
||||
|
||||
func (s *DB) First(out interface{}, where ...interface{}) *DB {
|
||||
return s.clone().do(out).where(where...).first().db
|
||||
scope := s.clone().NewScope(out)
|
||||
scope.Search = scope.Search.clone().order(scope.PrimaryKey()).limit(1)
|
||||
return scope.Set("gorm:inline_condition", where).callCallbacks(s.parent.callback.queries).db
|
||||
}
|
||||
|
||||
func (s *DB) Last(out interface{}, where ...interface{}) *DB {
|
||||
return s.clone().do(out).where(where...).last().db
|
||||
scope := s.clone().NewScope(out)
|
||||
scope.Search = scope.Search.clone().order(scope.PrimaryKey() + " DESC").limit(1)
|
||||
return scope.Set("gorm:inline_condition", where).callCallbacks(s.parent.callback.queries).db
|
||||
}
|
||||
|
||||
func (s *DB) Find(out interface{}, where ...interface{}) *DB {
|
||||
return s.clone().NewScope(out).Set("gorm:inline_condition", where).callCallbacks(s.parent.callback.queries).db
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue