Skip to content

Commit

Permalink
Merge pull request #46 from merixzon/master
Browse files Browse the repository at this point in the history
Allow specifying columns with Select() also when using Find()
  • Loading branch information
astaxie committed Dec 21, 2013
2 parents 8045e32 + d663719 commit c4c5a22
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions beedb.go
Expand Up @@ -150,10 +150,13 @@ func (orm *Model) Find(output interface{}) error {
if orm.TableName == "" {
orm.TableName = getTableName(StructName(output))
}
for key, _ := range results {
keys = append(keys, key)
// If we've already specific columns with Select(), use that
if orm.ColumnStr == "*" {
for key, _ := range results {
keys = append(keys, key)
}
orm.ColumnStr = strings.Join(keys, ", ")
}
orm.ColumnStr = strings.Join(keys, ", ")
orm.Limit(1)
resultsSlice, err := orm.FindMap()
if err != nil {
Expand Down Expand Up @@ -191,13 +194,13 @@ func (orm *Model) FindAll(rowsSlicePtr interface{}) error {
if orm.TableName == "" {
orm.TableName = getTableName(getTypeName(rowsSlicePtr))
}
// If we've already specific columns with Select(), use that
if orm.ColumnStr == "*" {
for key, _ := range results {
keys = append(keys, key)
}
orm.ColumnStr = strings.Join(keys, ", ")
}
// If we've already specific columns with Select(), use that
if orm.ColumnStr == "*" {
for key, _ := range results {
keys = append(keys, key)
}
orm.ColumnStr = strings.Join(keys, ", ")
}
resultsSlice, err := orm.FindMap()
if err != nil {
return err
Expand Down

0 comments on commit c4c5a22

Please sign in to comment.