ruby - How to describe belongs to many? -
I have three model class users, products and purchases. I describe the quantity of a product for the purchase order. So a purchase is a product, and a product may be related to many purchases, but the Mogoid message about the problem:
Mongoid :: Errors :: InverseNotFound (problem: when the # product If you add an (N) product to buy, you could not determine the inverted foreign key to set the muquidoid. Summary: When adding a document in a relationship, Mongoedd remembers the newly added document based on relationship in memory. Attempts to link, as well as sets the foreign key to add them from the database. This matter could not determine what was distracted foreign key: Resolution: If no inversions are needed, such as a_expression or has_and_belongs_to_many , Make sure that: inverse_of => is set to zero relationship. If inversion is required, then the most likely is the inverse address from the names of the relationships It can be applied only and you will need to be clearly told on the reverse relationships. Example: In a class flexible, Mongioid :: document contains: Whiskey, Class_name: "P", inverse_of :: alcoholic drinks at one end Subject: Monogoid :: Document contains: Aloe B, Class_name: "Lush", Inverse_off :: End of Whiskey): But do not believe my case, because I have "too much All "are relations.
This is my model:
class purchase includes MONGAID :: Document Field: Quantity, Text: String is_On: The product arrives: User's end-of-class product Monogead in :: Documents included: End of purchases is monoged in class user: document is_a: end of purchase How to describe relationships properly?
@zodzz is right that your relationships were backwards though, if you actually have a relationship value ( If you were looking for an HABT which only stores ID on one side of the relationship), then it can be implemented by:
has_and_belongs_to_many: name, inverse_of: zero View:
Comments
Post a Comment