Closed frankorama closed 7 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
Bug or feature request
Description of feature (or steps to reproduce if bug)
We have a model "TagGroup" which embeds a model "Tag" with an embeds many relationship:
.. such that a tag group (Book Type), can have many tags (Fiction, Biography, Non-Fiction, etc.)
When a new Tag Group is created, the ID is a BSON in MongoDB. When a new Tag is created, the ID is a string
Associating tags to books We associate Tags to Books using an array of strings because we were unable to figure out how to create a relation between a Model and an embedded model such that the books model looks like this:
When we associate tags to books, the data looks like this in Mongo:
Link to sample repo to reproduce issue (if bug)
(I can create one upon request)
Expected result
When I try to query a book by a tag in the explorer:
The loopback-connector-mongodb should convert the query to this:
... and locate the associated books
Actual result (if bug)
The loopback-connector-mongodb converts the query to this:
... and does not locate the associated books because the loopback-connector-mongodb detects if a value is an object id property by using a regular expression:
Additional information (Node.js version, LoopBack version, etc)
"loopback": "^2.37.1" "loopback-connector-mongodb": "^1.18.0" "loopback-datasource-juggler": "^2.54.0" MongoDB: 3.2
Questions about best-practice
Can/should embedsMany models be used as foreign keys? In my example should my TAGS model be a separate persisted model?
We did several tests trying to "relate" books and tags together, but were not successful. It would appear that embedsMany is useful for creating child objects that you want to copy to another document and never change once copied. Example: address on a shipping form. A user's address might change, but the address "copied" to the shipping form should never change once assigned, therefore no relationship.