forked from leancloud/cpp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVRelation.cpp
More file actions
68 lines (54 loc) · 1.75 KB
/
AVRelation.cpp
File metadata and controls
68 lines (54 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @file AVRelation.cpp
* @author yang chaozhong <cyang@avoscloud.com>
* @date Thu Aug 28 16:54:51 2014
*
* @brief
*
* Copyright 2014 AVOS Cloud Inc. All rights reserved.
*/
#include "AVObject/AVRelation.h"
#include <string>
NS_AV_BEGIN
AVQuery* AVRelation::query() {
Json::Value dict(Json::objectValue);
Json::Value relatedToDict(Json::objectValue);
Json::Value objectDict(Json::objectValue);
objectDict["__type"] = "Pointer";
objectDict["className"] = this->parent->className;
if (this->parent->hasValidObjectId()) {
objectDict["objectId"] = this->parent->objectId;
}
relatedToDict["object"] = objectDict;
relatedToDict["key"] = this->key;
dict["$relatedTo"] = relatedToDict;
AVQuery* query = AVQuery::queryWithClassName(this->targetClass);
query->setWhere(dict);
return query;
}
void AVRelation::release() {
AV_SAFE_DELETE(this);
}
void AVRelation::addObject(AVObject* object) {
if (object->hasValidObjectId()) {
this->targetClass = object->className;
this->parent->addRelationForKey(object, this->key);
}
}
void AVRelation::removeObject(AVObject* object) {
this->parent->removeRelationForKey(object, this->key);
}
AVQuery* AVRelation::reverseQueryWithRelationKeyAndChildObject(std::string parentClassName,
std::string relationKey,
AVObject* child) {
Json::Value objectDict(Json::objectValue);
objectDict["__type"] = "Pointer";
objectDict["className"] = child->className;
if (child->hasValidObjectId()) {
objectDict["objectId"] = child->objectId;
}
AVQuery* query = AVQuery::queryWithClassName(parentClassName);
query->setWhere(objectDict);
return query;
}
NS_AV_END