mongoid/mongoid — Issue #1487: Many To Many relations are not allowed between Referenced and Embedded relations
Author: lgs
Created: 2011-12-08 22:28:20+00:00
State: open

I've a User model embedding "one to many" Watchlists like the following :

class User
include Mongoid::Document

field :uid
field :name

embeds_many :watchlists
end

class Watchlist
include Mongoid::Document

field :html_url
field :description
field :created_at, :type => DateTime

embedded_in :user
has_and_belongs_to_many :tags
end

The Watchlist should also references a many to many Tag model and vice versa :

class Tag
include Mongoid::Document
field :name, type: String

has_and_belongs_to_many :watchlists
end

but that's causing an error and seems that kind of "mixed" relation is not possible ( but it should form my point of view ):

Mongoid::Errors::MixedRelations (Referencing a(n) Watchlist document from the Tag document via a relational association is not allowed since the Watchlist is embedded.):
app/controllers/home_controller.rb:53:in `tagging'