diff --git a/orm/query.go b/orm/query.go index 37ae194d..d9b39967 100644 --- a/orm/query.go +++ b/orm/query.go @@ -360,6 +360,30 @@ func (q *Query) ExcludeColumn(columns ...string) *Query { return q } +// AppendColumn appends column to the list of default columns if they weren't set, +// while Column method overrides defaults +func (q *Query) AppendColumn(columns ...string) *Query { + t := q.tableModel.Table() + if q.columns == nil { + for _, f := range t.Fields { + q.columns = append(q.columns, SafeQuery("?.?", t.Alias, f.Column)) + } + } + return q.Column(columns...) +} + +// AppendColumnExpr appends column expression to the list of default columns if they weren't set, +// while ColumnExpr method overrides defaults +func (q *Query) AppendColumnExpr(expr string, params ...interface{}) *Query { + t := q.tableModel.Table() + if q.columns == nil { + for _, f := range t.Fields { + q.columns = append(q.columns, SafeQuery("?.?", t.Alias, f.Column)) + } + } + return q.ColumnExpr(expr, params...) +} + func (q *Query) excludeColumn(column string) bool { for i := 0; i < len(q.columns); i++ { app, ok := q.columns[i].(fieldAppender)