{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/18301","labels_url":"https://api.github.com/repos/rails/rails/issues/18301/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/18301/comments","events_url":"https://api.github.com/repos/rails/rails/issues/18301/events","html_url":"https://github.com/rails/rails/issues/18301","id":53261322,"number":18301,"title":"Generated fixtures shouldn't include parent_id when generated with parent:references","user":{"login":"PaBLoX-CL","id":275754,"avatar_url":"https://avatars.githubusercontent.com/u/275754?v=3","gravatar_id":"","url":"https://api.github.com/users/PaBLoX-CL","html_url":"https://github.com/PaBLoX-CL","followers_url":"https://api.github.com/users/PaBLoX-CL/followers","following_url":"https://api.github.com/users/PaBLoX-CL/following{/other_user}","gists_url":"https://api.github.com/users/PaBLoX-CL/gists{/gist_id}","starred_url":"https://api.github.com/users/PaBLoX-CL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaBLoX-CL/subscriptions","organizations_url":"https://api.github.com/users/PaBLoX-CL/orgs","repos_url":"https://api.github.com/users/PaBLoX-CL/repos","events_url":"https://api.github.com/users/PaBLoX-CL/events{/privacy}","received_events_url":"https://api.github.com/users/PaBLoX-CL/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-02T16:24:38Z","updated_at":"2015-01-02T16:34:50Z","closed_at":null,"body":"I created two models:\r\n\r\n```yaml\r\n#test/fixtures/comments.yml\r\npablo:\r\n  commenter: Pablo\r\n  body: MyText\r\n  post_id: \r\n\r\nbenja:\r\n  commenter: Benja\r\n  body: MyText\r\n  post_id: \r\n```\r\n\r\n```yaml\r\n#test/fixtures/posts.yml\r\n\r\nabout:\r\n  title: MyString\r\n  body: MyText\r\n\r\nsecond:\r\n  title: MyString\r\n  body: MyText\r\n```\r\n\r\nAfter using the scaffold, I read the documentation about associations, and found that I should use label references instead \"fixed\" ids, so I tried to change it:\r\n\r\n```yaml\r\n  post_id: about\r\n```\r\n\r\nThis of course didn't work, and embarrassingly took me a while to discover why I was getting a `post_id` of `0`.\r\n\r\nWhile I understand generators are starting point, imho there's an inconsistency: if the generator is **not** creating `id` keys by default, why they are actually being created in `belongs_to` associations? I think it will make more sense that the generated file, in my example `test/fixtures/comments.yml` would be:\r\n\r\n```yaml\r\none:\r\n  commenter: MyString\r\n  body: MyText\r\n  post: \r\n\r\ntwo:\r\n  commenter: MyString\r\n  body: MyText\r\n  post: \r\n```\r\n\r\nIf this makes sense I can submit a PR, though I'm not sure if [generators/test_unit/model/templates/fixtures.yml](https://github.com/rails/rails/blob/master/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml) is the right place to change the logic... and I can't find how is that the generator skips the creation of the `id` key (I only found [a few](https://github.com/rails/rails/blob/master/railties/test/generators/model_generator_test.rb#L278-#L320) fixtures tests, but they didn't helped me)."},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/68539874","html_url":"https://github.com/rails/rails/issues/18301#issuecomment-68539874","issue_url":"https://api.github.com/repos/rails/rails/issues/18301","id":68539874,"user":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"created_at":"2015-01-02T16:34:50Z","updated_at":"2015-01-02T16:34:50Z","body":"Yes, that file is the correct place. You can use this method https://github.com/rails/rails/blob/78dab2a8569408658542e462a957ea5a35aa4679/railties/lib/rails/generators/generated_attribute.rb#L124 on attribute to know if it is a reference and do not put the id."}}