{"action":"created","issue":{"url":"https://api.github.com/repos/astaxie/beego/issues/384","labels_url":"https://api.github.com/repos/astaxie/beego/issues/384/labels{/name}","comments_url":"https://api.github.com/repos/astaxie/beego/issues/384/comments","events_url":"https://api.github.com/repos/astaxie/beego/issues/384/events","html_url":"https://github.com/astaxie/beego/issues/384","id":24400161,"number":384,"title":"Beego ORM模块建议","user":{"login":"phpqinsir","id":3759656,"avatar_url":"https://avatars.githubusercontent.com/u/3759656?v=3","gravatar_id":"","url":"https://api.github.com/users/phpqinsir","html_url":"https://github.com/phpqinsir","followers_url":"https://api.github.com/users/phpqinsir/followers","following_url":"https://api.github.com/users/phpqinsir/following{/other_user}","gists_url":"https://api.github.com/users/phpqinsir/gists{/gist_id}","starred_url":"https://api.github.com/users/phpqinsir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpqinsir/subscriptions","organizations_url":"https://api.github.com/users/phpqinsir/orgs","repos_url":"https://api.github.com/users/phpqinsir/repos","events_url":"https://api.github.com/users/phpqinsir/events{/privacy}","received_events_url":"https://api.github.com/users/phpqinsir/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":20,"created_at":"2013-12-17T05:00:48Z","updated_at":"2015-01-13T06:20:05Z","closed_at":null,"body":"例如，我有如下代码：\r\n\r\nvar hotCourse []models.VCourse\r\nsql = \"SELECT * FROM v_course ORDER BY hits DESC LIMIT 4\"\r\no.Raw(sql).QueryRows(&hotCourse)\r\n\r\n传入的hotCourse对应的models.VCourse里面的字段与数据库里面的字段顺序要一致才能将预期的字段值设置到VCourse的字段里面去。\r\n\r\n如：\r\ntype VCourse struct{\r\n  Id int64\r\n   Name string\r\n}\r\n\r\n那么sql语句里面必须SELECT id,name FROM table才能将字段的值绑定上去。这很不方便。\r\n\r\n我希望是这样的：\r\n当我的结构体只有两个字段：Id与Name,那么，在结果绑定到结构体上的时候，先遍历结构体的字段，按照Model的定义（即与表字段之间的定义）进行查找SQL里面的字段，然后将该字段的值绑定到结构体的对应字段上。这样就很完善了。\r\n\r\n在编写代码的时候，就不用再担心字段顺序的问题了。也不用担心，结构体的字段只有2个，而SQL字段有3个，导致匹配不上而报错了。\r\n\r\n能否请设计ORM的大神改善一下原生SQL语句的智能能力呢。谢谢！\r\n"},"comment":{"url":"https://api.github.com/repos/astaxie/beego/issues/comments/69700529","html_url":"https://github.com/astaxie/beego/issues/384#issuecomment-69700529","issue_url":"https://api.github.com/repos/astaxie/beego/issues/384","id":69700529,"user":{"login":"BlackLee","id":364380,"avatar_url":"https://avatars.githubusercontent.com/u/364380?v=3","gravatar_id":"","url":"https://api.github.com/users/BlackLee","html_url":"https://github.com/BlackLee","followers_url":"https://api.github.com/users/BlackLee/followers","following_url":"https://api.github.com/users/BlackLee/following{/other_user}","gists_url":"https://api.github.com/users/BlackLee/gists{/gist_id}","starred_url":"https://api.github.com/users/BlackLee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BlackLee/subscriptions","organizations_url":"https://api.github.com/users/BlackLee/orgs","repos_url":"https://api.github.com/users/BlackLee/repos","events_url":"https://api.github.com/users/BlackLee/events{/privacy}","received_events_url":"https://api.github.com/users/BlackLee/received_events","type":"User","site_admin":false},"created_at":"2015-01-13T06:20:05Z","updated_at":"2015-01-13T06:20:05Z","body":"用惯了Rails的ActiveRecord后再看Beego的，感觉相当的不便利。不奢望能在查询时返回ActiveRecord::Relation，但是至少能有ActiveRecord::Base里定义好的那么多便利的方法呀。"}}