-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Description
I created two models:
#test/fixtures/comments.yml
pablo:
commenter: Pablo
body: MyText
post_id:
benja:
commenter: Benja
body: MyText
post_id:
#test/fixtures/posts.yml
about:
title: MyString
body: MyText
second:
title: MyString
body: MyText
After 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:
post_id: about
This of course didn't work, and embarrassingly took me a while to discover why I was getting a post_id
of 0
.
While 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:
one:
commenter: MyString
body: MyText
post:
two:
commenter: MyString
body: MyText
post:
If this makes sense I can submit a PR, though I'm not sure if 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 fixtures tests, but they didn't helped me).