-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Using 3.1.0-stable
class Item include Mongoid::Document belongs_to :project recursively_embeds_many end class Project include Mongoid::Document has_many :items end
When trying to save a project you get:
Mongoid::Errors::MixedRelations:
Problem:
Referencing a Item document from the Project document via a relational association is not allowed since the Item is embedded.
Summary:
In order to properly access a Item from Project the reference would need to go through the root document of Item. In a simple case this would require Mongoid to store an extra foreign key for the root, in more complex cases where Item is multiple levels deep a key would need to be stored for each parent up the hierarchy.
Resolution:
Consider not embedding Item, or do the key storage and access in a custom manner in the application code.