-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Associations, Docs
-
None
The issue of association class name lookups when modules are involved has come up several times in my time at MongoDB, most recently in https://jira.mongodb.org/browse/MONGOID-5080. Our tutorial on the association page doesn't include the word "module" at all, hence appears to be silent on the matter.
Specifically, when models are defined in a module and they reference each other via associations, the class name must be specified on each reference where the target is in a module, even if the host is in the same module. For example, in the following snippet, both of the class_name options are required:
module Blog class Article include Mongoid::Document embeds_many :comments, class_name: "Blog::Comment" end class Comment include Mongoid::Document embedded_in :article, class_name: "Blog::Article" end end
This ticket is to:
Verify this behavior for all 7 associations (4 referenced, 3 embedded)
Add tests if needed
Document it in tutorial with examples
Note that https://jira.mongodb.org/browse/MONGOID-5080 proposes to change Mongoid's behavior to where :class_name option would be required when referencing models in non-host namespaces, which would require different documentation and tests.
- related to
-
MONGOID-5080 Inverses aren't found for embedded association in modules
- Backlog