0

I'm not completely new to Rails, but I'm taking another pass at all the basic guides in an exploratory repo I've been using to flush out my own knowledge.

I'm on this one right now: http://guides.rubyonrails.org/association_basics.html

I got to section "3.5 Bi-Directional Associations".

I understood that model instances could be duplicated and out-of-sync when accessed in two-different ways in the same process which is something I want to ensure I learn how to avoid.

So I wrote a simple unit test to detect the problem in this commit: https://github.com/BadQuanta/simple-rails/commit/5e88ff08d5ba2743c4dbcaa0479e9adc8edc2a1f

The unit test seemed to work since it failed with the error I expected.

So I implemented the fix prescribed by the guide in this commit: https://github.com/BadQuanta/simple-rails/commit/7ac75b45730e3230162b8da280ba713004b8745c

Yet my unit test still would not pass and I could not figure out why.

So I did this to my unit test and I'm kinda stumped because this is exactly what I thought I wouldn't have to do with these relationships: https://github.com/BadQuanta/simple-rails/commit/7ac75b45730e3230162b8da280ba713004b8745c

Basically, what can I do to figure out what I'm doing wrong?

4

1 回答 1

1

从相同的指导方针:

inverse_of 支持有一些限制:

  • 它们不适用于 :through 关联。
  • 它们不适用于 :polymorphic 关联。
  • 它们不适用于 :as 关联。
  • 对于belongs_to关联,has_many反向关联被忽略

那么为什么指南将它们用作示例

于 2012-09-01T11:27:40.810 回答