根据文档id获取一篇文档的全部信息 @param id 文档id @return params 文档信息 @return rows 记录数 @return err 错误
(id interface{})
| 184 | //@return rows 记录数 |
| 185 | //@return err 错误 |
| 186 | func (this *Document) GetById(id interface{}) (doc fullDocument, err error) { |
| 187 | var sql string |
| 188 | tables := []string{GetTableDocumentInfo() + " info", GetTableDocument() + " doc", GetTableDocumentStore() + " ds", GetTableUser() + " u"} |
| 189 | fields := map[string][]string{ |
| 190 | "ds": helper.DeleteSlice(GetFields(NewDocumentStore()), "Id"), |
| 191 | "info": GetFields(NewDocumentInfo()), |
| 192 | "u": {"Username", "Id Uid"}, |
| 193 | "doc": GetFields(NewDocument()), |
| 194 | } |
| 195 | on := []map[string]string{ |
| 196 | {"ds.Id": "info.DsId"}, |
| 197 | {"doc.Id": "info.Id"}, |
| 198 | {"u.Id": "info.Uid"}, |
| 199 | } |
| 200 | helper.Logger.Debug("查询字段:%+v", fields) |
| 201 | |
| 202 | sql, err = LeftJoinSqlBuild(tables, on, fields, 1, 1, nil, nil, "info.Id=?") |
| 203 | if err != nil { |
| 204 | helper.Logger.Error(err.Error()) |
| 205 | err = errors.New("内部错误:数据查询失败") |
| 206 | return |
| 207 | } |
| 208 | err = orm.NewOrm().Raw(sql, id).QueryRow(&doc) |
| 209 | return |
| 210 | } |
| 211 | |
| 212 | func (this *Document) GetDocument(id int, fields ...string) (doc Document) { |
| 213 | orm.NewOrm().QueryTable(this).Filter("Id", id).One(&doc, fields...) |
nothing calls this directly
no test coverage detected