Hi,I want to add item to existing table ,like in relation’s docs.But I am getting problem.
I will explain on your example.
When I want to add new contact to phone book,my client upload to server all phone book data.
What I am doing wrong?
Here my code
var dataStore_ = Backendless.Persistence.of(MyUser);
var myObject_ = new MyObject(args);
userItem['my_data'].push(myObject_ );
userItem= dataStore_ .save( userItem);
Please, try the following example, it`s fully functional. Take a look at attached screenshot with result of code execution.
/* classes */
function PhoneBook(args) {
args = args || {};
this.contacts = args.contacts || null; // collection of Contacts
}
function Contact(args) {
args = args || {};
this.___class = 'Contact';
this.name = args.name || "";
this.age = args.age || "";
this.phone = args.phone || "";
this.title = args.title || "";
}
/* classes */
/* example */
var phoneBookStorage = Backendless.Persistence.of(PhoneBook);
var John = new Contact({
name: "John",
age: 27,
phone: "1-800-MY-APPLE",
title: "common contact"
});
var contacts = [];
contacts.push(John);
var phoneBook = phoneBookStorage.save(new PhoneBook({contacts: contacts}));
/* example */
My case little bit another.
Consider this,in another part of code you want to add another contact to PhoneBook. And you don’t have the previous phoneBookStorage
If you want to add ‘Contact’ to ‘PhoneBook’ - you must obtain reference to ‘PhoneBook’.
It may be a javascript instance property or something else, giving you the ability to address ‘PhoneBook’ when needed.
function PhoneBook(args) {
args = args || {};
this.contacts = args.contacts || null;
}
<MyApplicationClass>.phoneBookStorage = Backendless.Persistence.of(PhoneBook);
<MyApplicationClass>. phoneBook = <MyApplicationClass>.phoneBookStorage.save(new PhoneBook());
....
<MyApplicationClass>.phoneBook.contacts.push(new Contact());
<MyApplicationClass>.phoneBookStorage.save(<MyApplicationClass>.phoneBook);
Thanks Eugene,it occurred that your first comment was enough to solve my problem.
Thanks