Skip to content

× Error: You cannot add or remove an unsaved Parse Object from a relation #703

Closed
@Molyktech

Description

@Molyktech

hello, I am trying to create a relation between to classes with parse but no matter what I try, I keep getting the error;
Error: You cannot add or remove an unsaved Parse Object from a relation

here is the code
let Institution = Parse.Object.extend("Institution");
let institution = new Institution();
let InstitutionType = Parse.Object.extend("InstitutionType");
let instType = new InstitutionType();
let {
companyName,
companyEmail,
phoneNumber,
companyRegNumber,
type,
regPhoneNumber,
serviceModule,
category
} = this.state;
institution.set("serviceModule", serviceModule);
institution.set("category", category);
institution.set("createdBy", handler);
institution.set("type", type);

institution.save().then(
  institution => {
    alert("institution saved");
  },
  error => {
    alert("institution failed " + error.message);
  }

);
instType.set("name", type);
instType.set("serviceModule", serviceModule);
instType.set("parent", institution);
instType.save().then(
instType => {
alert("instType saved");
},
error => {
alert("failed due to: " + error.message);
}
);

let relation = institution.relation("institutionType");
relation.add(instType);
relation.save();
// note that when i define institution by setting it to new Parse.Object("Institution); i still get the same error.

//
I tried the relation method in the while saving the institution but instType was undefined, I tried it vice versa and still got the same thing. i decided to call the method after both classes have been saved but still no hope. please what am i doing wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions