-
Type:
Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
I have Post model that holds viewer_ids and a User model that holds viewed_ids.
viewer_ids got contain user objects and viewed_ids contain post objects.
#Post class belongs_to :user has_and_belongs_to_many :viewers, class_name: 'User', inverse_of: :viewed #User class has_many :posts has_and_belongs_to_many :viewed, class_name: 'Post', inverse_of: :viewers
I tested this relation using Rspec to read, write, and delete from both sides and it works. while updating the inverse of the relation just fine.
The problem i found was when i get to use RABL to view list of posts. I render each post with user data embedded in each post. So when i remove child user it works.
child :user do extends "users/base" end
If i get this error
Problem: Ambiguous relations :posts, :viewed defined on User. Summary: When Mongoid attempts to set an inverse document of a relation in memory, it needs to know which relation it belongs to. When setting :user, Mongoid looked on the class Post for a matching relation, but multiples were found that could potentially match: :posts, :viewed. Resolution: On the :user relation on Post you must add an :inverse_of option to specify the exact relationship on User that is the opposite of :user.
Am I doing something wrong, or is it a bug? BTW it gives the same error in the html response too.