示例#1
0
    def add(self, *obj_or_objs):
        """
        添加一个新的 leancloud.Object 至 Relation。

        :param obj_or_objs: 需要添加的对象或对象列表
        """
        objs = obj_or_objs
        if not isinstance(obj_or_objs, (list, tuple)):
            objs = (obj_or_objs, )
        change = operation.Relation(objs, ())
        self.parent.set(self.key, change)
        self.target_class_name = change._target_class_name
示例#2
0
    def remove(self, *obj_or_objs):
        """
        从一个 Relation 中删除一个 leancloud.Object 。

        :param obj_or_objs: 需要删除的对象或对象列表
        :return:
        """
        objs = obj_or_objs
        if not isinstance(obj_or_objs, (list, tuple)):
            objs = (obj_or_objs, )
        change = operation.Relation((), objs)
        self.parent.set(self.key, change)
        self.target_class_name = change._target_class_name
示例#3
0
def test_apply_relation_op():
    album = leancloud.Object.create("Album",
                                    objectId="abc001",
                                    title="variety")
    band1 = leancloud.Object.create("Band", objectId="abc101", name="xxx")
    band2 = leancloud.Object.create("Band", objectId="abc102", name="ooo")

    relation = album.relation("band")

    op = operation.Relation([band1], [band2])
    val = op._apply(None, album, "band")
    assert isinstance(val, leancloud.Relation)
    val._ensure_parent_and_key(album, "band")

    val = op._apply(relation)
    assert isinstance(val, leancloud.Relation)
    val._ensure_parent_and_key(album, "band")