当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Parse Add Exist Object to Table

问题描述:

I started to use Parse.com for my first Cordova Application

I got a problem with Relation.

I have a table "Employee" contain all my employees.

And i have too a table "Expense", contain all expense of my employees.

Each expense will connect to one employee, and one employee can have many expenses.

So i created a column "ExpenseBy" in Expense table , type Pointer to table Employee.

But when i created a new expense, i can not add an exist employee to this field (ExpesnseBy). The Parse'systeme always create new employee.

Please help me !

Thank all.

网友答案:

The issue is most likely due to how you are loading the employee. You simply have to first load the employee and then when you create the expense you set the ExpenseBy field to the employee:

var Employee = Parse.Object.extend("Employee");
var Expense = Parse.Object.extend("Expense");
var query = new Parse.Query(Employee);

query.get("xWMyZ4YEGZ", {
  success: function(employee) {
    var expense = new Expense();

    expense.set("ExpenseBy", employee);
    expense.save();
  },
  error: function(object, error) {
    // The object was not retrieved successfully.
    // error is a Parse.Error with an error code and message.
  }
});

More information is available from the documentation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: