Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
mongoiderrorsmixedrelations ¬†using -'ruby-on-rails,mongodb,mongoid'
I've a User model embedding "one to many" Watchlists like the following :
¬†¬†field :name ¬†¬†¬†¬†
¬†¬†field :fork_, :type => Boolean
¬†¬†field :forks, :type => Integer
¬†¬†field :watchers, :type => Integer
¬†¬†field :created_at, :type => DateTime
¬†¬†field :pushed_at, :type => DateTime
The Watchlist should also references a many to many Tag model and vice versa :
¬†¬†field :name, type: String
Anyway, that's causing an error and seems that kind of "mixed" relation is not possible :
Mongoid::Errors::MixedRelations (Referencing a(n) Watchlist document from the Tag document via a relational association is not allowed since the Watchlist is embedded.):
Please note that watchlist, has to be dropped (user.watchlists.clear) than re-created (user.watchlists.find_or_create_by) four times a day, while Tag/s have to be persistent, relating the same embedded watchlists as before ( ... I'm not sure that is possible anyway, because of previous drop/creation ).
UPDATE of UPDATE ( tanks to durran support )
No, that's not possible: If you clear the embedded docs, the ids are gone as well, and new ones will get generate each time you create a new one.
Do you have any idea on how to overcome that ?
Is it better to split all three models in referenced relations ( three different collections )?
Oct 13, 2015
to add a comment.
Related Hot Questions
Government Jobs Opening