Support Topics Documentation Slack YouTube Blog

Error updating Data Service


(Raul Claudino) #1

Hello guys,

I’m having a problem updating my table after making a relationship with geolocation:

var ads = Backendless.Persistence.of(new $rootScope.Classes.Ads()).findById('MY_ID');

ads.active = 0;       
var result = Backendless.Persistence.of(new $rootScope.Classes.Ads()).save(ads); 





It returns the error: “error: Missing ___class property for entity: position”

(position is a relationship object with Geolocation)

$rootScope.Classes.Ads():

Ads: function Ads( args ){
args = args || {};                
this.___class = "Ads";
            	            
this.position = args.position || null;


...................



(Maryna Marin) #2

Hello, Raul! You should to determine class Ads, like this:

Ads: function Ads( args ){
args = args || {};
this.___class = "Ads";
this.position= new GeoPoint();

Also you cannot change column type from relations to other. You should
remove object and than again save it, with new property. For example,
this example work perfectly:

 
	 

 
	function Ads(args) { 
 
	 



 
	args= args || {}; 
 
	 



 
	this.___class= "Ads"; 
 
	 



 
	this.position= new GeoPoint(); 
 
	 



 
	} 
 
	 



 
 
 



 
	var ads = new Ads();
 
	 



 
 
 



 
	var geoPoint = new GeoPoint();
 
	 



 
	geopoint.latitude= 40.72;
 
	 



 
	geopoint.longitude= -74;
 
	 



 
 
 



 
	ads.position= geoPoint;
 
	 



 
	Backendless.Persistence.of(Ads).save(ads); 
 




(Raul Claudino) #3

I can make an update on Ads without creating a new GeoPoint?


(Mark Piller) #4

You can save (create or update) an instance of Ads without any value in the “position” field.


(Raul Claudino) #5

Mark,

I realized that this error occurs when I create the relationship by Backendless Console.


(Maryna Marin) #6

Raul, you are right! You got exception, because you determine field “position” in main class “Ads” as column type (it can be “string”, “text”, “integer”, “boolean”, “double” or “datetime”), but not “relation” type. To avoid this exception you should declare the “position” field in class “Ads” as “new GeoPoint()”. This doesn’t mean, that you should create new GeoPoint every time, when you want update an instance of Ads. This means, that you should save to field “position” just instance of GeoPoint class.
Record

this.position = args.position || null;

it means, that you want dynamically determine type of field position. That is possible, but you can determine type of field position, just when you create an instance of Ads class. But then you can’t change type of field, when you update instance of Ads.


(Mark Piller) #7

Raul,

Does it answer your question?

Regards,
Mark


(Raul Claudino) #8

Mark,

The problem is that I need add the property .___class = ‘GeoPoint’.
This is right or this property should come already added?

var ads = Backendless.Persistence.of(new $rootScope.Classes.Ads()).findById('F96D5EF5-D23F-2397-FFDB-10C399841300');


ads.location.___class = 'GeoPoint';


ads.active = 0;


Backendless.Persistence.of(new $rootScope.Classes.Ads()).save(ads));

(Mark Piller) #9

Raul,

backendless.js already includes a definition of GeoPoint and it already defines ___class. Just look for this code in backendless.js:

var GeoPoint = function () {
    this.___class = "GeoPoint";
    this.categories = undefined;
    this.latitude = undefined;
    this.longitude = undefined;
    this.metadata = undefined;
    this.objectId = undefined;
};

Try debugging your code and make sure that when you create GeoPoint the code steps into backendless.js.


(Raul Claudino) #10

Mark,

You’re right, when we create a new GeoPoint he has the __CLASS.

But when we do a search:

var ads = Backendless.Persistence.of(new $rootScope.Classes.Ads()).findById('F96D5EF5-D23F-2397-FFDB-10C399841300');
console.log('result ads', ads);

(look at the attachment)
I compared ‘location’ with ‘kind_of_conditions’. What do you think?


(Raul Claudino) #11

Hello guys,

Do you have any news about this?


(Mark Piller) #12

Hi Raul,

I apologize, I dropped the ball on this one. I understand what happens now. A temporary workaround is just like you suggested - adding that missing property to your geopoint objects:

ads.location.___class = 'GeoPoint';

I am scheduling an internal ticket to review the code and make sure it is done automatically.

Regards,
Mark


(Raul Claudino) #13

Thank you Mark.


(Kate Maksimenko) #14

Hi Raul!
This issue already resolved. Please try it again.


(Jonathan Ngabo) #15

Hello,
I’m having the same problem, could you guys help me please?
here is the log: “error: Missing ___class property for entity: dataMapper”

My table looks like this.

 
 
 
 
 
 
 
 
function Recipe( args ){ 
 
		 args = args || {}; 
 
		 
 
		 this.created = args.created || null; 
 
		 this.Duration = args.Duration || null; 
 
		 this.objectId = args.objectId || null; 
 
		 this.Ingredients = args.Ingredients || null; 
 
		 this.Description = args.Description || null; 
 
		 this.Title = args.Title || null; 
 
		 this.Categorie = args.Categorie || null; 
 
		 this.updated = args.updated || null; 
 
		 this.ownerId = args.ownerId || null; 
 
		 this.Photo = args.Photo || null; 
 
		 this.Likes = args.Likes || null; 
 
 
 
 
		 this._private_relations = []; 
 
		 this._private_geoRelations = []; 
 
		 this._private_dates = [ 
 
		 "created", 
 
		 "updated"]; 
 
		 this.___class = "Recipe"; 
 
 
 
 
		 
 
		 var storage = Backendless.Persistence.of( Recipe ); 
 
 
 
 
		 this.save = function ( async ) 
 
		 { 
 
		 cleanPrivateRelations(this); 
 
		 storage.save( this, async ); 
 
		 }; 
 
 
 
 
		 this.remove = function ( async ) 
 
		 { 
 
		 var result = storage.remove( this, async ); 
 
		 this.objectId = null; 
 
		 return result; 
 
		 }; 
 
 
 
		}


And this is my script

 
 
 
 
 
 
 
 
var storage = Backendless.Persistence.of( Recipe ); 
 
 				var dataQuery2 = { 
 
						condition: "objectId = '"+this.parentNode.parentNode.children[2].childNodes[1].className+"'" 
 
	 			} 
 
				var recipesUpdate = Backendless.Persistence.of(Recipe).find(dataQuery2); 
 
				var likeN = recipesUpdate.data[0].Likes + 1; 
 
 
 
 
				recipesUpdate["Likes"]=likeN; 
 
 				storage.save(recipesUpdate); 




(Mark Piller) #16

Could you capture the entire request body in a browser (use Network tab in chrome’s developer tools) and post it here?


(Jonathan Ngabo) #17

Hello Mark,
It’s ok now, thanks.