Merge pull request #1092 from hjlarry/patch-1

Update 05.5.md
This commit is contained in:
astaxie
2019-06-21 08:31:05 +08:00
committed by GitHub

View File

@@ -218,12 +218,12 @@ type Tag struct {
func init() {
// 需要在init中注册定义的model
orm.RegisterModel(new(Userinfo),new(User), new(Profile), new(Tag))
orm.RegisterModel(new(Userinfo),new(User), new(Profile), new(Post), new(Tag))
}
```
>注意一点beego orm针对驼峰命名会自动帮你转化成下划线字段例如你定义了Struct名字为`UserInfo`,那么转化成底层实现的时候是`user_info`,字段命名也遵循该规则。
>注意一点beego orm针对驼峰命名会自动帮你转化成下划线字段例如你定义了struct名字为`UserInfo`,那么转化成底层实现的时候是`user_info`,字段命名也遵循该规则。
## 插入数据
下面的代码演示了如何插入一条记录可以看到我们操作的是struct对象而不是原生的sql语句最后通过调用Insert接口将数据保存到数据库。
@@ -287,7 +287,7 @@ o.Update(&user, "Name")
// o.Update(&user, "Field1", "Field2", ...)
```
//Where:用来设置条件支持多个参数第一个参数如果为整数相当于调用了Where("主键=?",值)。
Where: 用来设置条件支持多个参数第一个参数如果为整数相当于调用了Where("主键=?",值)。
## 查询数据
beego orm的查询接口比较灵活具体使用请看下面的例子
@@ -384,7 +384,7 @@ num, err := qs.Filter("User__Name", "slene").All(&posts)
## Group By和Having
## GroupBy和Having
针对有些应用需要用到group by的功能beego orm也提供了一个简陋的实现
```Go