V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
LeanCloud
LeanCloud
scarlex
V2EX  ›  LeanCloud

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

  •  
  •   scarlex · Sep 25, 2015 · 4099 views
    This topic created in 3867 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
        1
    juvenn  
       Oct 8, 2015
    Relation 是支持同时 add 和 remove 的,错误的原因可能是有 item 同时出现在了 add 和 remove 的数组里。
    scarlex
        2
    scarlex  
    OP
       Oct 11, 2015
    @juvenn
    的确是有些 item 同时出现在 add 和 remove 里面了。
    但你们文档里面不是说会保证唯一性么,那同时 add 和 remove 为啥会报错?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   946 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 21:16 · PVG 05:16 · LAX 14:16 · JFK 17:16
    ♥ Do have faith in what you're doing.