astaxie/beego — pull request #475 by kylemcc (2014-01-22 06:19:05+00:00)
Title: Add a ReadOrCreate method:

Stealing this pattern from Django - I think it is common enough to warrant having a helper method as part of the API.

ReadOrCreate will take struct defining some fields, and one or more column names to search on. If the object is found based on the search criteria, it will be returned. Otherwise, the object will be inserted and returned.

```
m := &User{Name: "Kyle", Email: "kylemcc@gmail.com", City: "Chicago"}
// Returns a boolean indicating whether the object was created,
// the primary key of the object, or an error.
created, id, err := orm.ReadOrCreate(m, "Name")
```

Let me know what you think. If this is acceptable, I'll make a pull request to update the documentation as well.