-
Notifications
You must be signed in to change notification settings - Fork 42
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
Posting multi level schemas #27
Comments
@pehaada and I were discussing this and think there may be a bug when posting more than 2 "levels" deep. Using the example from the readme, posting to
will work fine, however if you add another level like
or in your case
then there seems to be some issues in the routes.js file for the router.post.
However, I'm not sure my solution is the most elegant or best way to do so. router.post(reGet, function (req, res, next) {
res.contentType('json');
var single = req.query.single;
var stuff = [].concat(req.params);
stuff.shift();
var Model = m(req.params[0]);
var qo = idObj(req.params[1]);
var pos = req.params[2] && req.params[2].split('/');
var find = Model.findOne(qo);
find.exec(function (err, obj) {
if (err)return next(err);
var put = clean(req.body), orig = [].concat(pos);
console.log(put);
if (pos) {
var o = obj
// while (o && pos.length - 1) {
// o = o[pos.shift()]
// }
// if (o[pos[0]] instanceof Array) {
// o[pos[0]].push(put);
// } else {
// o[pos[0]] = put;
// }
// obj.markModified(orig.join('.'));
//BEGIN CHANGE
var evalString = "obj";
while (o && pos.length > 0) {
var shiftVar = pos.shift();
if (o[shiftVar] instanceof Array) {
evalString += "." + shiftVar
o = o[shiftVar];
} else {
evalString += '.id("' + shiftVar +'")'
o = _u.findWhere(o, {id: shiftVar});
}
}
if (eval(evalString) instanceof Array) {
eval(evalString).push(put);
} else {
eval(evalString) = put;
}
//END CHANGE
} else {
_u.extend(obj, put);
}
obj.save(function (err, ret) {
res.contentType('json');
if (err) {
console.log("error saving ", err, err.stack);
res.send({
status: 1,
message: err.message
});
} else {
var obj = ret.toJSON();
if (pos) {
while (obj && orig.length) {
obj = obj[orig.shift()];
}
}
res.send({
status: 0,
payload: Array.isArray(obj) ? obj.pop() : obj
})
}
});
});
}); @jspears Does this seem like a good solution? I've commented out the existing code and included mine above. Please forgive me if this is a poor way of requesting a change, I'm new to github and am not too familiar with etiquette around change or pull requests, except that I'm pretty sure that my this isn't the way to do it 😃 |
Awesome I'll have to take a closer look, but thank you... I am happy Thanks! On Fri, May 9, 2014 at 1:17 PM, Matt notifications@github.com wrote:
|
Thanks! I figured out how to make a pull request, so I submitted that. |
I believe this is fixed in 0.9 + sorry about that... I have tests, that work! Thanks for the patch |
This might be a dumb question, but i'm trying to contruct a post that can save an "advanced" schema.
My schema looks like this:
What should my post look like to create an
openinghours
on my Activity?i tried this, but it just created an activity without openinghours
The text was updated successfully, but these errors were encountered: