Last sorts rows by primary key and selects the last row. It is a shortcut for: q.OrderExpr("id DESC").Limit(1)
()
| 825 | // |
| 826 | // q.OrderExpr("id DESC").Limit(1) |
| 827 | func (q *Query) Last() error { |
| 828 | table := q.tableModel.Table() |
| 829 | |
| 830 | if err := table.checkPKs(); err != nil { |
| 831 | return err |
| 832 | } |
| 833 | |
| 834 | // TODO: fix for multi columns |
| 835 | b := appendColumns(nil, table.Alias, table.PKs) |
| 836 | b = append(b, " DESC"...) |
| 837 | return q.OrderExpr(internal.BytesToString(b)).Limit(1).Select() |
| 838 | } |
| 839 | |
| 840 | // Select selects the model. |
| 841 | func (q *Query) Select(values ...interface{}) error { |