deleting relationships with rest

Hi I’m some doubts regarding the relationship tables, I can access the child class attributes through the parent class? I am trying to delete a parent class via rest, with a http angularjs the service, and also wanted to exclude the child class attached to it, I’m trying to do already have some time already tried to study the documentation a few times but I still do not get to do. Thanks for listening

Hi Murillo,

Could you please share some sample code that demonstrates what you’re doing?

Regards,
Mark

managed to solve my problem, but I have another question, I can remove a relationship, without removing the objects? thanks for listening, and excuse the delay in response, in fact did not know he had answered my question, I did not get any notification to me

If you use rest, you can “unlink” two related objects by saving the “parent” object with the collection of children where one of the “child” objects is removed from the collection.

Regards,
Mark

I do not know if I understand, you are saying that I should pick up the collection and save again, but removing the object from the collection do not want?

Let me try to explain myself with a “symbolic” example.

Suppose you load an object like this:

{
“objectId”:“XXXX-XXXX-XXXX-XXXX”,
“name”:“Joe”,
“age”:45,
“fooCollection”:[A,B,C,D],
“__meta”:"…"
}

and you need to remove “D” from the “fooCollection”. In order to do this, you need to save the object with all the same properties, but without D in the collection:

{
“objectId”:“XXXX-XXXX-XXXX-XXXX”,
“name”:“Joe”,
“age”:45,
“fooCollection”:[A,B,C],
“__meta”:"…"
}

Notice that D is no longer in the collection. It is also very important that the “__meta” property is sent back when you save it.

Hope this helps.

Mark

I had already tried to resend a new collection but did not work out, but I used the service “PUT” and not sent to _meta property, the right would I use the “POST”?

You need to use PUT and it is important to send the __meta property to the server when you’re updating an object with relations.

ok, thank you very much for your help, I will try to apply what you told me

I’m having serious problems to work with __meta, you would have some material that I can study, to learn how to work with it, because I’m already sending a new collection without the object that do not want to, but still does not work, I believe the problem is with him, but I know nothing about it

Can you show me an example of the requests you send? (with URL, headers and JSON body)

As for __meta, there is nothing special you need to do. Just get the value you receive from Backendless and send the same value back to our server. That is all.

var _updateTurma = function(objectId,turma){
return $http.put('https://api.backendless.com/v1/data/Turmas/’+objectId, turma,
{

		headers:{
			'application-id': '6FE67292-F413-9B0A-FF75-FD3594DF2300',
			'secret-key'    : '27C738CA-2AE7-F02B-FFCA-7BEC526B9A00',
			'Content-Type':'application/json'
		}
		
	}).error(function(data){
		console.log(data);


	});
}

turma={
“aluTurma”:novo

	}

well, where is your collection of related objects?

and where is the __meta element in the body?

the “novo” is the collection with objects and “aluTurma” is the relationship, I’m just passing it because it’s the only thing I want to edit

I do not know manipulate the __meta and the “new” will pass the code I am doing…

$scope.mudarTurma = function(aluno,turma){
	var achado;
	for (var i = 0; i < $scope.turmas.length; i++) {
		for (var y = 0; y < $scope.turmas.aluTurma.length; y++) {
			if($scope.turmas.aluTurma[y].objectId == aluno.objectId){
				$scope.cont = i;
				achado = true;
				break;
			}
		}


	if(!achado){
		alert("Este aluno não está cadastrado em nenhuma turma")
		$window.location.reload()
	}




	var novo = $scope.turmas.map(function(elemento){
		for (var i = 0; i < elemento.aluTurma.length; i++) {
			if(elemento.aluTurma.objectId !=aluno.objectId){
				return elemento.aluTurma
			}			
		};
	})
	for (var i = novo.length; 1 < i ; i--) {
		if(novo == undefined){
			novo.pop();




		}
	}


	


	console.log($scope.turmas[$scope.cont].__meta)


	turma={
		"aluTurma":novo,
	}


	turmasAPI.updateTurma($scope.turmas[$scope.cont].objectId,turma).success(function(response,data){
		alert("Turma editada com sucesso");
		console.log(data);
	});


}

You do not need to “manipulate” __meta. Just take what Backendless sends you and sent it back. Without any changes.

work … you are simply the best, I am ashamed to not be able to do something so simple. In addition to you be sensational tool, support is also very good, congratulations on the great work

I am glad you got it working. Thank you for your kind words.

Please, help me to delete link relation:


	$.ajax({
		url: 'https://api.backendless.com/v1/data/Users/1E056A5A-F0F2-F153-FF03-0CBC8765E200',  
		type: 'PUT',
		headers: {
			'application-id':"2C9C3B50-FE23-FA0F-FFE1-222ADFEDD600",
			'secret-key':"F2B0F631-68E6-4F9B-FF9C-01B923F63500",
		},
		contentType: "application/json; charset=utf-8", 
		data: {"Create":[{"___class":"Items", "objectId":"7804AA43-D036-61EF-FF10-4813CA086500"},{"___class":"Items", "objectId":"4A74864C-C9F5-6AE5-FFE2-D10D80EBCB00"}]},//"__meta":"Create:4A74864C-C9F5-6AE5-FFE2-D10D80EBCB00,7804AA43-D036-61EF-FF10-4813CA086500,45B1EE14-FBA2-B3AF-FFCC-294DE1653D00",
		crossDomain: true,
		dataType: 'json',
		success: function() { alert('PUT completed'); }
	});

It is:
PUT https://api.backendless.com/v1/data/Users/1E056A5A-F0F2-F153-FF03-0CBC8765E200 400 (Bad Request)

ok, my mistake is missing quotes:

data: '{"__meta":"Create:4A74864C-C9F5-6AE5-FFE2-D10D80EBCB00,7804AA43-D036-61EF-FF10-4813CA086500,45B1EE14-FBA2-B3AF-FFCC-294DE1653D00","Create":[{"___class":"Items", "objectId":"7804AA43-D036-61EF-FF10-4813CA086500"},{"___class":"Items", "objectId":"4A74864C-C9F5-6AE5-FFE2-D10D80EBCB00"}]}'

and success reuest, but relation is not removed