{"action":"created","issue":{"url":"https://api.github.com/repos/astaxie/beego/issues/1281","labels_url":"https://api.github.com/repos/astaxie/beego/issues/1281/labels{/name}","comments_url":"https://api.github.com/repos/astaxie/beego/issues/1281/comments","events_url":"https://api.github.com/repos/astaxie/beego/issues/1281/events","html_url":"https://github.com/astaxie/beego/issues/1281","id":97019620,"number":1281,"title":"orm在执行read的时候报错","user":{"login":"pchenghao","id":5679494,"avatar_url":"https://avatars.githubusercontent.com/u/5679494?v=3","gravatar_id":"","url":"https://api.github.com/users/pchenghao","html_url":"https://github.com/pchenghao","followers_url":"https://api.github.com/users/pchenghao/followers","following_url":"https://api.github.com/users/pchenghao/following{/other_user}","gists_url":"https://api.github.com/users/pchenghao/gists{/gist_id}","starred_url":"https://api.github.com/users/pchenghao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pchenghao/subscriptions","organizations_url":"https://api.github.com/users/pchenghao/orgs","repos_url":"https://api.github.com/users/pchenghao/repos","events_url":"https://api.github.com/users/pchenghao/events{/privacy}","received_events_url":"https://api.github.com/users/pchenghao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-24T10:13:50Z","updated_at":"2015-07-24T13:41:52Z","closed_at":null,"body":"model的代码如下：\r\n// blog.go\r\npackage models\r\n\r\nimport (\r\n\t\"github.com/astaxie/beego/orm\"\r\n\t_ \"github.com/go-sql-driver/mysql\"\r\n\t\"time\"\r\n)\r\n\r\nconst(\r\n\tPAGE_SIZE = 10\r\n)\r\n\r\ntype BlogContent struct{\r\n\tId \t\t\t\tint\t\t\t`orm:\"auto\"`\r\n\tUser\t\t\t*User \t\t`orm:\"rel(fk);null;on_delete(set_null)\"` //外键对应值删除时，些记录不删除，设置为null\r\n\tTitle\t\t\tstring\r\n\tType \t\t\tstring\t\t`orm:\"null\"`\r\n\tLabel\t\t\tstring\t\t`orm:\"null\"`\r\n\tContent\t\t\tstring\t\t`orm:\"null;type(text)\"`\r\n\tTop\t\t\t\tstring\t\t`orm:\"null\"`\r\n\tPublicTime\t\ttime.Time\t`orm:\"null;auto_now_add;type(datetime)\"` //第一次保存时设置时间\r\n\tLastModifyTime\ttime.Time\t`orm:\"null;auto_now;type(datetime)\"` //每次保存时自动更新时间\r\n\tState\t\t\tint\t\t\t`orm:\"default(1)\"`\r\n}\r\n\r\ntype User struct {\r\n\tId\t\t\t\tint\t\t\t`orm:\"auto\"`\r\n\tUsername\t\tstring\r\n\tPassword\t\tstring\r\n\tLevel\t\t\tint\t\t\t`orm:\"default(0)\"`\r\n}\r\n\r\nvar o orm.Ormer\r\n\r\nfunc init(){\r\n\t//注册模型\r\n\torm.RegisterModel(new(BlogContent), new(User))\r\n\t//初始化Orm\r\n\torm.RegisterDataBase(\"default\", \"mysql\", \"root:123456@/blog?charset=utf8\")\r\n\torm.RunSyncdb(\"default\", false, true)\r\n\t//初始化Orm对象\r\n\to = orm.NewOrm()\r\n}\r\n\r\n//分布查询博客\r\nfunc GetBlogsByPage(pageNo int) (blogs []*BlogContent,err error){\r\n\tif pageNo == 0 {\r\n\t\tpageNo = 1\r\n\t}\r\n\tfrom := (pageNo - 1) * PAGE_SIZE + 1\r\n\tto := pageNo * PAGE_SIZE\r\n\t_,err = o.QueryTable(\"blog_content\").Filter(\"state\", 1).OrderBy(\"top\", \"-lastmodifytime\").Limit(to, from).All(&blogs)\r\n\treturn\r\n}\r\n\r\n//根据Id查询博客\r\nfunc GetBlogById(id int) (blog *BlogContent, err error){\r\n\tblog = &BlogContent{Id: id}\r\n\terr = o.Read(&blog) //这里会报错\r\n\treturn\r\n}\r\n\r\n\r\n调用GetBlogById函数时会报错：Handler crashed with error <Ormer> table: `.` not found, maybe not RegisterModel \r\n在init中已经注册过BlogContent，并且在使用GetBlogsByPage函数时正常。\r\n求大神帮忙看一下，谢谢。"},"comment":{"url":"https://api.github.com/repos/astaxie/beego/issues/comments/124524503","html_url":"https://github.com/astaxie/beego/issues/1281#issuecomment-124524503","issue_url":"https://api.github.com/repos/astaxie/beego/issues/1281","id":124524503,"user":{"login":"pchenghao","id":5679494,"avatar_url":"https://avatars.githubusercontent.com/u/5679494?v=3","gravatar_id":"","url":"https://api.github.com/users/pchenghao","html_url":"https://github.com/pchenghao","followers_url":"https://api.github.com/users/pchenghao/followers","following_url":"https://api.github.com/users/pchenghao/following{/other_user}","gists_url":"https://api.github.com/users/pchenghao/gists{/gist_id}","starred_url":"https://api.github.com/users/pchenghao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pchenghao/subscriptions","organizations_url":"https://api.github.com/users/pchenghao/orgs","repos_url":"https://api.github.com/users/pchenghao/repos","events_url":"https://api.github.com/users/pchenghao/events{/privacy}","received_events_url":"https://api.github.com/users/pchenghao/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T13:41:52Z","updated_at":"2015-07-24T13:41:52Z","body":"感谢你的帮助，已经解决。\r\n顺便请教下，是不是一般传对象的时候传指针？这样会更节省内存吗？之前是做java的，对指针不太理解，望简单指教下什么情况下用指针。我知道的有需要改变对象内部值的时候会传指针。"}}