LeanCloud
LeanCloud
scarlex
V2EX  ›  LeanCloud

LeanCloud 中的 Relation 是不能同时 add 和 remove 的么?

  •  
  •   scarlex · Sep 25, 2015 · 4665 views
    This topic created in 4060 days ago, the information mentioned may be changed or developed.

    代码:

    post.relation('items').remove(_items);
    post.relation('items').add(items);
    post.save().then(function(p) {
        res.send(p);
    }, function(err) {
        console.log(err);
    });
    

    结果:

    { code: 1, message: 'Invalid op.' }
    

    但我单独执行 .remove(_items) 和 .add(items) 是不会报错的。

    2 replies  •  2015-10-11 11:27:12 +08:00
    juvenn
    juvenn
    Oct 8, 2015
    1
    Relation 是支持同时 add 和 remove 的,错误的原因可能是有 item 同时出现在了 add 和 remove 的数组里。
    scarlex
    scarlex
    OP
    Oct 11, 2015
    2
    @juvenn
    的确是有些 item 同时出现在 add 和 remove 里面了。
    但你们文档里面不是说会保证唯一性么,那同时 add 和 remove 为啥会报错?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1864 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:34 · PVG 09:34 · LAX 17:34 · JFK 20:34
    ♥ Do have faith in what you're doing.