Closed gdlx closed 10 years ago
My models didn't work that well: I've forgotten foreign_key
definitions in my associations...now everything works without even specifying class_name
and with_foreign_key
...
Okay, glad you were able to figure it out. It sounds like there's an error message that's missing on our side that would have made things easier for you? In other words, were you getting a "expected Company::Project::Group to have a has_many association called members" message even though the association was defined in your model?
By the way: class_name
and with_foreign_key
never need to be added to the matchers, but doing so will add extra checks.
Yes, I think a message explaining that the foreign key field doesn't exists on the belonging side could help troubleshooting the issue.
In my case, the message could have been (in both cases): "Company::Project::Member should have a group_id
foreign key", because that was the default foreign key, which wasn't the one defined in my migrations.
Thanks !
@mcmire Hi. I am a bit confused about this. I think the expected behavior is that it identifies the foreign key that the relationship should have based on where the class is located. In the case of Company::Project::Group
the default foreign key is company_project_group_id
. So I think it could be something that could be improved.
@DiegoOrejuela It sounds like the OP was able to solve his problem, so that's why I closed this particular issue, but it's possible there is still a bug here — I would need more information to know for sure. So if you are getting this error I think what would be most helpful is a complete example of the association in your model and the tests you have in your test file. Preferably also in a new issue :)
I can't make
have_many
/belong_to
work with namespaced models associations.I'm using model classes like
Company::Project::Group
has_many
Company::Project::Members
When testing this:
I get this (as expected):
I change my test to this:
The
company_project_group_id
field exists, but I still get this error:As you can see, there's no error detail so I don't know why the test is failing... I get the same behavior testing the inverse
belongs_to
relation:Using rails-4.1.6, active-record 4.1.6 w/ MySQL, rspec-rails-3.1.0, shoulda-matchers 2.7.0
Nothing special in my models associations:
Am I doing something wrong ?