-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do embedded manys work? #8
Comments
Unfortunately minimongoid is still pretty basic, and hasn't been set up to be very sophisicated, so things like what you're trying to do here have a somewhat unintuitive mechanism. In order to save an embedded many, you have to perform a mongo search_term = SearchTerm.create {valid_data: ...}
search_term.push {results: {some_result_data: ...}} Otherwise to perform a save, the save method requires you to pass in whatever attributes you're trying to save, it does not know what has been changed based on running a search_term.results.push new_result
search_term.update {results: search_term.results} In that case you'd be overwriting the search_term.results altogether with the new array. I have to recommend though you probably want to stick to saving the data you're trying to save (option 1) and not actually pushing a minimongoid instantiated model to your save methods, otherwise you may run into the need to use JSON.decycle to prevent any circular references (i.e. search_term embeds_many results which are embedded_in search_term which embeds_many results...) So, two things that have not been implemented in minimongoid which would be useful here are:
This has come up in some other issues (#2, #5, #12). This project isn't something that I'm spending a lot of time on, just something in my free time, so if anyone wants to work on some of these features and submit a pull request, that would be most awesome... |
I can't seem to figure out how to save an embedded many relation on an object.
When I create a SearchTerm and then push a javascript object onto results, it won't save. I would think just using push would save it? If not, I've tried called searchTerm.save() on my object, but the resulting object has empty results when I instantiate it.
The text was updated successfully, but these errors were encountered: