1

Docs say it is required to create relation type column in the dashboard prior to adding any relations to object:

In the Data Browser, you can create a column on the Book object of type relation and name it authors.

Is it possible to create it from js sdk level? I tried something like here:

book.save(null).then(saved => {
  let relation = new Parse.Relation(saved.id, "authors");
  relation.add(author);
  saved.save(null);
}

But it can not be saved saying TypeError: this.parent.set is not a function

I know I can add it manually in the dashboard as stated, but the idea is to create new classes automatically.

2 Answers 2

2

If you want to add a relation with the Javascript Parse SDK you need to work directly with your object:

For example:

var user = Parse.User.current();
var relation = user.relation("mylikes");
relation.add(post); // Post is a Parse Object
user.save();

In your case, I think you want something like that:

book.save(null).then(saved => {
    var relation = saved.relation("authors");
    relation.add(author);
    saved.save(null);
}

I hope my answer was helpful 😊

Sign up to request clarification or add additional context in comments.

2 Comments

I was sure I tried it at the beginning. It seems sometimes data browser doesn't show latest updates. Thanks!
@BartBiczBoży You're welcome, If you want to refresh your object you can use the fetch method
0

I will Show you how to add a pointer and relation in 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()};

  }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.