如何在 Parse-SDK-JS 中使用关系创建新的 Parse.Object
How to create new Parse.Object with relation in Parse-SDK-JS
Docs 表示需要在向对象添加任何关系之前在仪表板中创建关系类型列:
In the Data Browser, you can create a column on the Book object of
type relation and name it authors.
是否可以从js sdk级别创建?我在这里试过类似的东西:
book.save(null).then(saved => {
let relation = new Parse.Relation(saved.id, "authors");
relation.add(author);
saved.save(null);
}
但是不能保存说TypeError: this.parent.set is not a function
我知道我可以按照说明在仪表板中手动添加它,但我的想法是自动创建新的 类。
如果您想添加与 Javascript Parse SDK 的关系,您需要直接使用您的对象:
例如:
var user = Parse.User.current();
var relation = user.relation("mylikes");
relation.add(post); // Post is a Parse Object
user.save();
在你的情况下,我想你想要这样的东西:
book.save(null).then(saved => {
var relation = saved.relation("authors");
relation.add(author);
saved.save(null);
}
希望我的回答对您有所帮助
我将向您展示如何在 Parse 中添加指针和关系
Parse.User.currentAsync().then((current) => {
if (current) {
var pharmacy = new Parse.Object("Pharmacy");
// add a pointer here
pharmacy.set("owner", current);
pharmacy
.save()
.then((pharmacy) => {
// add a relation here
var relation = current.relation("pharmacy");
relation.add(pharmacy)
current.save()};
}
});
Docs 表示需要在向对象添加任何关系之前在仪表板中创建关系类型列:
In the Data Browser, you can create a column on the Book object of type relation and name it authors.
是否可以从js sdk级别创建?我在这里试过类似的东西:
book.save(null).then(saved => {
let relation = new Parse.Relation(saved.id, "authors");
relation.add(author);
saved.save(null);
}
但是不能保存说TypeError: this.parent.set is not a function
我知道我可以按照说明在仪表板中手动添加它,但我的想法是自动创建新的 类。
如果您想添加与 Javascript Parse SDK 的关系,您需要直接使用您的对象:
例如:
var user = Parse.User.current();
var relation = user.relation("mylikes");
relation.add(post); // Post is a Parse Object
user.save();
在你的情况下,我想你想要这样的东西:
book.save(null).then(saved => {
var relation = saved.relation("authors");
relation.add(author);
saved.save(null);
}
希望我的回答对您有所帮助
我将向您展示如何在 Parse 中添加指针和关系
Parse.User.currentAsync().then((current) => {
if (current) {
var pharmacy = new Parse.Object("Pharmacy");
// add a pointer here
pharmacy.set("owner", current);
pharmacy
.save()
.then((pharmacy) => {
// add a relation here
var relation = current.relation("pharmacy");
relation.add(pharmacy)
current.save()};
}
});