{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/18492","labels_url":"https://api.github.com/repos/rails/rails/issues/18492/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/18492/comments","events_url":"https://api.github.com/repos/rails/rails/issues/18492/events","html_url":"https://github.com/rails/rails/issues/18492","id":54236119,"number":18492,"title":"Fixtures not working with single table inheritance","user":{"login":"macarenomarco","id":4233076,"avatar_url":"https://avatars.githubusercontent.com/u/4233076?v=3","gravatar_id":"","url":"https://api.github.com/users/macarenomarco","html_url":"https://github.com/macarenomarco","followers_url":"https://api.github.com/users/macarenomarco/followers","following_url":"https://api.github.com/users/macarenomarco/following{/other_user}","gists_url":"https://api.github.com/users/macarenomarco/gists{/gist_id}","starred_url":"https://api.github.com/users/macarenomarco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/macarenomarco/subscriptions","organizations_url":"https://api.github.com/users/macarenomarco/orgs","repos_url":"https://api.github.com/users/macarenomarco/repos","events_url":"https://api.github.com/users/macarenomarco/events{/privacy}","received_events_url":"https://api.github.com/users/macarenomarco/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/activerecord","name":"activerecord","color":"0b02e1"},{"url":"https://api.github.com/repos/rails/rails/labels/attached%20PR","name":"attached PR","color":"006b75"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-13T19:26:37Z","updated_at":"2016-01-08T23:09:42Z","closed_at":"2015-02-01T02:05:05Z","body":"I've found that when using single table inheritance it's necessary to use a single fixture file for all the test objects of that particular inheritance tree. For example when using a base class Person and Two child classes Student and Teacher, the expected behavior would be that when loading the files `teacher.yml` and `students.yml` the table people would have all the fixtures in it. The following are some simple files to explain it.\r\n\r\n```yaml\r\n#teachers.yml\r\npresto:\r\n    name: Test Teacher\r\n```\r\n\r\n```yaml\r\n#students.yml\r\ntesto:\r\n    name: Test Person\r\n    teacher: presto\r\n```\r\n\r\nHowever when loading this fixtures only the teacher fixture exists in the database, after some messing around with the fixtures API and console I found that only the last fixtures of the table are that ones that are kept, which in default behaviour is the teachers fixtures because of the alphabetical loading order. Moreover, if the last fixture file is an empty one, the table stays empty.\r\n\r\n Maybe I didn't find it, but when researching it I saw no mention of this behavior in the docs.\r\n\r\nThe workaround I've found to work, is to use a single fixture file for any table that uses single table inheritance and erasing all other fixture files for the subclasses, or to load them explicitly by calling the fixtures API."},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/170153031","html_url":"https://github.com/rails/rails/issues/18492#issuecomment-170153031","issue_url":"https://api.github.com/repos/rails/rails/issues/18492","id":170153031,"user":{"login":"wyde19","id":8819524,"avatar_url":"https://avatars.githubusercontent.com/u/8819524?v=3","gravatar_id":"","url":"https://api.github.com/users/wyde19","html_url":"https://github.com/wyde19","followers_url":"https://api.github.com/users/wyde19/followers","following_url":"https://api.github.com/users/wyde19/following{/other_user}","gists_url":"https://api.github.com/users/wyde19/gists{/gist_id}","starred_url":"https://api.github.com/users/wyde19/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wyde19/subscriptions","organizations_url":"https://api.github.com/users/wyde19/orgs","repos_url":"https://api.github.com/users/wyde19/repos","events_url":"https://api.github.com/users/wyde19/events{/privacy}","received_events_url":"https://api.github.com/users/wyde19/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T23:09:42Z","updated_at":"2016-01-08T23:09:42Z","body":"Will this be backported to Rails4, or should we use some kind of workaround?"}}