Skip to content

Commit

Permalink
实现relation查询
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuanrong committed May 12, 2018
1 parent 5963a7b commit 4499ff2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
44 changes: 24 additions & 20 deletions src/lib/relation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,30 @@ const relation = class Relation {
remove(parmas) {
return operation.call(this, parmas, 'RemoveRelation')
}
// field(objectId, field) {
// if (!isString(objectId) || !isString(field)) {
// throw new error(415)
// }
// this.whereData.where = {
// "$relatedTo": {
// "object": {
// "__type": "Pointer",
// "className": this.tableName,
// "objectId": objectId
// },
// "key": field
// }
// }
// }
// find(){
// request(`/1/${this.tableName}`,'get',this.whereData).then(res => {
// console.log(res);
// })
// }
field(tableName,objectId, field) {
if (!isString(objectId) || !isString(field)) {
throw new error(415)
}
this.whereData.where = {
"$relatedTo": {
"object": {
"__type": "Pointer",
"className": tableName,
"objectId": objectId
},
"key": field
}
}
}
find(){
return new Promise((resolve,reject) => {
request(`/1/${this.tableName}`,'get',this.whereData).then(({results}) => {
resolve(results)
}).catch(err => {
reject(err)
})
})
}
}

function operation(parmas, op) {
Expand Down
17 changes: 6 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,13 @@ Bmob.User.login('admin','123456').then(res => {
console.log(err)
});

// const Relation = Bmob.Relation('_User')
// Relation.field('a312d300eb','two')
// Relation.find()
const Relation = Bmob.Relation('users')
Relation.field('abcd','a312d300eb','two')
Relation.find().then(res => {
console.log(res);
})
// const id = own.unset('73d4587140')
// const query = Bmob.Query('abcd');
// query.get('a312d300eb').then(res => {
// res.set('two',id)
// res.save()
// })
// query.find().then(res => {
// console.log(res);
// })


// query.get('c02b7b018f').then(res => {
// console.log(res);
Expand Down

0 comments on commit 4499ff2

Please sign in to comment.