Comments (3)
FYI I accidentally posted that using a client's github account. My apologies. I am actually the OP for the above.
from moonridge.
@WolfieWerewolf thanks for the report. Lodash certainly can have some unwanted behaviour. We should come up with a simple testcase and include it in the fix. Can you give me a sample of how the data looks like before you call update on your model and how do you expect them to look after that update?
from moonridge.
@capaj thanks for your positive reply, I'm happy to help in any way I can. This is all dummy data so no privacy concerns; I'm getting my output from logging inside mr-rpc.methods.js.
In this case there were two mrClients associated with the quote. Aaron Wolf and Andrew Wolf as seen here in:
previousVersion
mrClient_ids: [ 56520dd781715c8057c3c768, 56520dd781715c8057c3c783 ] }
toUpdate shows the object, which had been populated, with Andrew Wolf removed; it contains only Aaron Wolf.
mrClient_ids:
[ { _id: '56520dd781715c8057c3c768',
rider_id: '56520dd481715c8057c3b5b9',
linkedin_id: 'This is some address',
facebook_id: '......',
skype_id: '[email protected]',
email: '[email protected]',
post_code: '4250',
state: 'QLD',
locality: 'SomeLocality',
street_name: 'Jemmy Rd',
house_number: '2318',
rider: true,
occupation: 'Senior Party Coordinator',
mobile: '0455655543',
landline: '0566677766',
lastname: 'Wolf',
firstname: 'Aaron',
__v: 5,
mrQuote_ids: [Object],
mrRider_id: [Object],
mrRider: true } ] }
Notice that, as it is fully populated it contains all of the data and not just the _id that is to be stored in the mrClient_ids array.
Here is doc after the _merge
{ mrClient_ids: [ 56520dd781715c8057c3c768, 56520dd781715c8057c3c783 ],
It has stripped all of the populated data but has failed to remove the _id for Andrew Wolf. So the update was not successful.
Now here is the output using the fix I described above for the same operation:
previousVersion
mrClient_ids: [ 56520dd781715c8057c3c768, 56520dd781715c8057c3c783 ] }
toUpdate
mrClient_ids: [ '56520dd781715c8057c3c768' ] }
doc
{ mrClient_ids: [ 56520dd781715c8057c3c768 ],
Note that in addition to replacing _merge with the plainjs snippet I provided, server side, I also performed the following "cleaning operation" on the client before calling update. This is an AngularJs front end but should be pretty self explanatory. The following is in my $scope.serialize = function(){}
var mrClientIds = [];
$scope.quoteRow.mrClient_ids.forEach(function(clientIds){
mrClientIds.push(clientIds._id);
})
$scope.quoteRow.mrClient_ids = mrClientIds
mrService.mrquoteModel.update($scope.quoteRow);
mrService is just an Angular factory service that I put together to wrap the MoonRidge client so I can inject it throughout my app.
The best possible outcome would be to somehow inform the MoonRidge server about which objects have been populated and have it perform the "cleaning" operation that I have done manually, to strip out only the objectId's that the schema is expecting and replace all the populated data, before attempting to do the merge.
The model had previously been populated as follows:
var query = mrService.mrquoteModel.query()
.find({ _id: id})
.populate('mrClient_ids')
.populate('broker_id')
.populate('mrRider_id')
var promise = query.exec();
promise.then(function (doc) {
$scope.quoteRow = doc[0]; //It's only expecting one result.
.........
Before attempting to make any serious changes to your framework I thought it best to open this discussion as you will certainly have a better idea for how to approach this than I would.
If anything is unclear or you require any further information please let me know.
Kind Regards
/W
from moonridge.
Related Issues (12)
- add exists event HOT 1
- implement canOnlyReadOwned permission flag HOT 1
- disallow changing createdDate field within mongoose pre hook
- Help in integrating with mean.js stack HOT 4
- Simple example HOT 1
- Cannot connect from remote browser HOT 2
- Updating records on a filtered result. HOT 2
- have common handler for all the mongo calls which would handle errors by default
- client methods are not needed as RPC calls, implement it with event emitter over socket.io
- `npm test` fails because missing dependency `morgan` HOT 1
- add aggregate support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moonridge.