Last finds the last record ordered by primary key, matching given conditions conds
(dest interface{}, conds ...interface{})
| 156 | |
| 157 | // Last finds the last record ordered by primary key, matching given conditions conds |
| 158 | func (db *DB) Last(dest interface{}, conds ...interface{}) (tx *DB) { |
| 159 | tx = db.Limit(1).Order(clause.OrderByColumn{ |
| 160 | Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey}, |
| 161 | Desc: true, |
| 162 | }) |
| 163 | if len(conds) > 0 { |
| 164 | if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 { |
| 165 | tx.Statement.AddClause(clause.Where{Exprs: exprs}) |
| 166 | } |
| 167 | } |
| 168 | tx.Statement.RaiseErrorOnNotFound = true |
| 169 | tx.Statement.Dest = dest |
| 170 | return tx.callbacks.Query().Execute(tx) |
| 171 | } |
| 172 | |
| 173 | // Find finds all records matching given conditions conds |
| 174 | func (db *DB) Find(dest interface{}, conds ...interface{}) (tx *DB) { |