{"action":"created","issue":{"url":"https://api.github.com/repos/jinzhu/gorm/issues/143","labels_url":"https://api.github.com/repos/jinzhu/gorm/issues/143/labels{/name}","comments_url":"https://api.github.com/repos/jinzhu/gorm/issues/143/comments","events_url":"https://api.github.com/repos/jinzhu/gorm/issues/143/events","html_url":"https://github.com/jinzhu/gorm/issues/143","id":35779091,"number":143,"title":"Dynamic data loading (reflect: call of reflect.Value.FieldByName on map Value)","user":{"login":"ahirmayur","id":703113,"avatar_url":"https://avatars.githubusercontent.com/u/703113?v=3","gravatar_id":"","url":"https://api.github.com/users/ahirmayur","html_url":"https://github.com/ahirmayur","followers_url":"https://api.github.com/users/ahirmayur/followers","following_url":"https://api.github.com/users/ahirmayur/following{/other_user}","gists_url":"https://api.github.com/users/ahirmayur/gists{/gist_id}","starred_url":"https://api.github.com/users/ahirmayur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahirmayur/subscriptions","organizations_url":"https://api.github.com/users/ahirmayur/orgs","repos_url":"https://api.github.com/users/ahirmayur/repos","events_url":"https://api.github.com/users/ahirmayur/events{/privacy}","received_events_url":"https://api.github.com/users/ahirmayur/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jinzhu/gorm/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-06-16T09:11:05Z","updated_at":"2015-11-11T07:06:04Z","closed_at":"2015-10-13T08:26:30Z","body":"Hi guys,\r\n\r\nI have a dynamic query where the structure of table is not knows in advance.\r\n\r\ne.g.\r\n```\r\nresults := make(map[string]interface{}, 0)\r\nerr := DB.Table(table).Find(&results).Error\r\n```\r\n\r\n```table``` is a variable passed by user on runtime.\r\n\r\nDoing so creates a Panic,\r\n\r\n```reflect: call of reflect.Value.FieldByName on map Value```"},"comment":{"url":"https://api.github.com/repos/jinzhu/gorm/issues/comments/155687294","html_url":"https://github.com/jinzhu/gorm/issues/143#issuecomment-155687294","issue_url":"https://api.github.com/repos/jinzhu/gorm/issues/143","id":155687294,"user":{"login":"jinzhu","id":6843,"avatar_url":"https://avatars.githubusercontent.com/u/6843?v=3","gravatar_id":"","url":"https://api.github.com/users/jinzhu","html_url":"https://github.com/jinzhu","followers_url":"https://api.github.com/users/jinzhu/followers","following_url":"https://api.github.com/users/jinzhu/following{/other_user}","gists_url":"https://api.github.com/users/jinzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/jinzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jinzhu/subscriptions","organizations_url":"https://api.github.com/users/jinzhu/orgs","repos_url":"https://api.github.com/users/jinzhu/repos","events_url":"https://api.github.com/users/jinzhu/events{/privacy}","received_events_url":"https://api.github.com/users/jinzhu/received_events","type":"User","site_admin":false},"created_at":"2015-11-11T07:06:04Z","updated_at":"2015-11-11T07:06:04Z","body":"OK, so this is not a normal case (you don't even care fields, data type)\r\n\r\nSo some code like this doesn't seem pain to me, if still think about pain, write a wrapper for this.\r\n\r\n```go\r\nvar results []map[string]interface{}\r\ncols, err := rows.Columns()\r\n\r\nfor rows.Next() {\r\n\tvar row = make([]interface{}, len(cols))\r\n\trows.Scan(row...)\r\n\r\n\trowMap := make(map[string]interface{})\r\n\tfor i, col := range cols {\r\n\t\trowMap[col] = row[i]\r\n\t}\r\n\r\n\tresults = append(results, rowMap)\r\n}\r\n```"}}