{"action":"created","issue":{"url":"https://api.github.com/repos/jinzhu/gorm/issues/796","labels_url":"https://api.github.com/repos/jinzhu/gorm/issues/796/labels{/name}","comments_url":"https://api.github.com/repos/jinzhu/gorm/issues/796/comments","events_url":"https://api.github.com/repos/jinzhu/gorm/issues/796/events","html_url":"https://github.com/jinzhu/gorm/issues/796","id":125852340,"number":796,"title":"Deep populate (Nested Eager Loading) only poplating the first element of the slice","user":{"login":"Gacnt","id":3466546,"avatar_url":"https://avatars.githubusercontent.com/u/3466546?v=3","gravatar_id":"","url":"https://api.github.com/users/Gacnt","html_url":"https://github.com/Gacnt","followers_url":"https://api.github.com/users/Gacnt/followers","following_url":"https://api.github.com/users/Gacnt/following{/other_user}","gists_url":"https://api.github.com/users/Gacnt/gists{/gist_id}","starred_url":"https://api.github.com/users/Gacnt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gacnt/subscriptions","organizations_url":"https://api.github.com/users/Gacnt/orgs","repos_url":"https://api.github.com/users/Gacnt/repos","events_url":"https://api.github.com/users/Gacnt/events{/privacy}","received_events_url":"https://api.github.com/users/Gacnt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-01-10T23:11:18Z","updated_at":"2016-01-13T01:03:04Z","closed_at":null,"body":"```\r\npackage main\r\n\r\nimport (\r\n\t\"log\"\r\n\r\n\t_ \"github.com/go-sql-driver/mysql\"\r\n\t\"github.com/jinzhu/gorm\"\r\n)\r\n\r\nvar db gorm.DB\r\n\r\ntype User struct {\r\n\tgorm.Model\r\n\tUsername     string `sql:\"not null;unique\"`\r\n\tEmail        string `sql:\"not null;unique\"`\r\n\tPasswordHash string `sql:\"not null;unique\"`\r\n\tUserLevel    int    `sql:\"not null;default:1\"`\r\n\tCharacters   []Characters\r\n\tMainPosts    []ForumMainThreadsPosts\r\n\tReplyPosts   []ForumMainPostsReplies\r\n}\r\n\r\n// Characters is a table in the database\r\ntype Characters struct {\r\n\tgorm.Model\r\n\tUserID             int    `sql:\"index\"`\r\n\tCharacterName      string `sql:\"not null;unique\"`\r\n\tCharacterServer    string `sql:\"not null\"`\r\n\tCharacterLevel     int    `sql:\"not null\"`\r\n\tCharacterMain      bool   `sql:\"not null\"`\r\n\tCharacterClass     string `sql:\"not null\"`\r\n\tCharacterPic       string `sql:\"not null\"`\r\n\tCharacterSpec      string `sql:\"not null\"`\r\n\tCharacterCSSClass  string `sql:\"not null\"`\r\n\tCharacterTalentImg string `sql:\"not null\"`\r\n}\r\n\r\n// ForumMainPostsReplies is a table in the database\r\ntype ForumMainPostsReplies struct {\r\n\tgorm.Model\r\n\tForumMainThreadsPostsID int `sql:\"index\"`\r\n\tUserID                  int `sql:\"index\"`\r\n\tForumMainThreadsPosts   ForumMainThreadsPosts\r\n\tUser                    User\r\n\tBody                    string\r\n}\r\n\r\n// ForumMainThreadsPosts is a table in the database\r\ntype ForumMainThreadsPosts struct {\r\n\tgorm.Model\r\n\tUserID             int `sql:\"index\"`\r\n\tForumMainThreadsID int `sql:\"index\"`\r\n\tUser               User\r\n\tForumMainThreads   ForumMainThreads\r\n\tTitle              string `sql:\"not null;unique\"`\r\n\tBody               string `sql:\"type:text;not null\"`\r\n\tSticky             bool   `sql:\"not null;default:0\"`\r\n\tViews              int    `sql:\"not null;default:0\"`\r\n\tReplyCount         int    `sql:\"not null;default:0\"`\r\n\tReplies            []ForumMainPostsReplies\r\n}\r\n\r\n// ForumMainThreads is the table in the database\r\ntype ForumMainThreads struct {\r\n\tgorm.Model\r\n\tForumContainerID int    `sql:\"index\"`\r\n\tThreadName       string `sql:\"not null;unique\"`\r\n\tThreads          int    `sql:\"not null;default:0\"`\r\n\tReplies          int    `sql:\"not null;default:0\"`\r\n\tAccessLevel      int    `sql:\"not null;default:0\"`\r\n\tPosts            []ForumMainThreadsPosts\r\n}\r\n\r\n// NewsFeed is the news that people will see when first\r\n// visiting the page\r\ntype NewsFeed struct {\r\n\tgorm.Model\r\n\tUserID int `sql:\"index\"`\r\n\tUser   User\r\n\tTitle  string\r\n\tBody   string `sql:\"type:text\"`\r\n}\r\n\r\nfunc init() {\r\n\tvar err error\r\n\tdb, err = gorm.Open(\"mysql\", \"dethronedadmin:9vAzvxWbpZEUd^@(pugit.net:3306)/dethroned?parseTime=true\")\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\tdb.LogMode(true)\r\n\r\n\t// db.AutoMigrate(&User{}, &Characters{},\r\n\t// \t&ForumMainThreads{}, &ForumMainThreadsPosts{}, &ForumMainPostsReplies{}, &NewsFeed{})\r\n}\r\n\r\nfunc main() {\r\n\r\n\tposts := []ForumMainThreadsPosts{}\r\n\tif err := db.Order(\"created_at desc\").Preload(\"User.Characters\").Limit(10).Find(&posts).Error; err != nil {\r\n\t\tlog.Println(err)\r\n\t}\r\n\r\n\tlog.Printf(\"Posts: %+v\", posts)\r\n\r\n\tlog.Println(\"Finished\")\r\n\r\n}\r\n\r\n```\r\n\r\nOnly the first element is getting their `Characters` populated:\r\n\r\n```\r\n[2016-01-10 15:59:52]  [245.46ms]  SELECT  * FROM `characters`  WHERE (`characters`.deleted_at IS NULL OR `characters`.deleted_at <= '0001-01-02') AND ((user_id IN ('48','5','30','13','51','31','4','5','5','5')))\r\n```"},"comment":{"url":"https://api.github.com/repos/jinzhu/gorm/issues/comments/171117900","html_url":"https://github.com/jinzhu/gorm/issues/796#issuecomment-171117900","issue_url":"https://api.github.com/repos/jinzhu/gorm/issues/796","id":171117900,"user":{"login":"Gacnt","id":3466546,"avatar_url":"https://avatars.githubusercontent.com/u/3466546?v=3","gravatar_id":"","url":"https://api.github.com/users/Gacnt","html_url":"https://github.com/Gacnt","followers_url":"https://api.github.com/users/Gacnt/followers","following_url":"https://api.github.com/users/Gacnt/following{/other_user}","gists_url":"https://api.github.com/users/Gacnt/gists{/gist_id}","starred_url":"https://api.github.com/users/Gacnt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gacnt/subscriptions","organizations_url":"https://api.github.com/users/Gacnt/orgs","repos_url":"https://api.github.com/users/Gacnt/repos","events_url":"https://api.github.com/users/Gacnt/events{/privacy}","received_events_url":"https://api.github.com/users/Gacnt/received_events","type":"User","site_admin":false},"created_at":"2016-01-13T01:03:04Z","updated_at":"2016-01-13T01:03:04Z","body":"jesus christ..... I wonder if this is related the Sequel Pro GUI, remove \r\n\r\n```\r\n\r\n/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\r\n/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\r\n/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r\n/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\r\n/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r\n\r\n```\r\n\r\nfrom the bottom of the sql dump, imported just fine for me"}}