rails 4 When is "inverse

I am developing a web app using rails 4 for the first time. I am making all of my model associations bidirectional and using inverse_of wherever it is allowed.

From reading the documentation, I've developed the impression that this is probably the best practice, but that's never really spelled out clearly anywhere.

I'd appreciate any general advice in this regard from experienced rails developers. I hope the question is not too vague to have value here.

Thanks!

Update : In addition to non-standard names, there appear to be two main additional cases where explicitly setting inverse_of is needed:

  • for INVALID_AUTOMATIC_INVERSE_OPTIONS ( http://www.rubydoc.info/docs/rails/ActiveRecord/Reflection/AssociationReflection )
  • if you're accepting nested attributes - This is because the parent object is not saved yet and thus does not have an id. See http://viget.com/extend/exploring-the-inverse-of-option-on-rails-model-associations

  • It is typically desirable to have inverses set up. The good news is that this is handled automatically in most cases. You usually only need to explicitly set the inverses for associations with non-standard names. You can find out a lot more in the official documentation.

    链接地址: http://www.djcxy.com/p/28156.html

    上一篇: SQL Server的复杂选择查询

    下一篇: 导轨4什么时候是“反向”