jxmono / crud

:fork_and_knife: CRUD for mono
MIT License
0 stars 1 forks source link

_id is required when inserting something via bind-crud #3

Closed IonicaBizau closed 11 years ago

IonicaBizau commented 11 years ago

I want to insert a new list using bind-crud.

My crud object looks like this:

{
    "t": "_list",
    "d": {
        "_tp": "_list",
        "name": "New Articles",
        "type": "fixed",
        "_ln": [
            {
                "_tp": "_template",
                "_id": "article"
            }
        ]
    }
}

Bind-crud throws Error: Missing required field: _id. Why? I guess that the _id of this object will be generated, being a MongoId.

Is this a bug or my mistake?

ottiker commented 11 years ago

Do you do something like this self.emit('update', {/*crud*/}, function () {}) ? Or can you give me a link to the code which makes the request?

IonicaBizau commented 11 years ago

I use insert parameter.

self.emit("insert", crudObj, function (err, insertedDoc) { ... });
IonicaBizau commented 11 years ago
    //////////////////////
    // NEW LIST/NEW FOLDER
    //////////////////////
    DmsTree.newList = function (listObj, callback) {

        if (!currentTemplate) { return alert("Select a template, first."); }

        listObj._ln = [
            {
                _tp: "_template",
                _id: currentTemplate._id
            }
        ];

        var crudObj = {
            t: "_list",
            d: listObj
        };

        DmsTree.emit("insert", crudObj, function (err, insertedDoc) {

            if (err) {
                alert(err);
                return;
            }

            if (callback) { callback(err, insertedDoc); }
            DmsTree.emit("newListInserted", listObj);
        });
    };

(from dms-tree, main.js)

IonicaBizau commented 11 years ago

This is obsolete now.