Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restangular flattening models on post?

Say I have the following form comprising a model and a nested model:

<label>Company Name</label>
<input type="text" ng-model="company.name" />

<label>Owner Name</label>
<input type="text" ng-model="company.owner.name" />

Which I post like this:

Restangular.all('companies').post($scope.company);

What I'm expecting on the server end (in this case Rails) is a nested hash something like this:

company:
    name: Test Company
    owner:
        name: Test Owner

But what I'm getting is this:

name: Test Company
company:
    name: Test Company
owner:
    name: Test Owner

It appears that the models are being flattened, and also the fields from the first model are repeated outside of the scoping.

How can I post the model whilst maintaining its nesting and preferably not repeating the models fields outside of its scope in the hash?

like image 850
matthewrk Avatar asked Jul 11 '13 14:07

matthewrk


1 Answers

I'm the creator of Restangular.

Could you console.log the output of $scope.company?

Restangular isn't flattering anything. It's just sending the exact JSon that you've provided as a parameter, that's why you should check what is the output of $scope.company.

After that, we can check it further.

Also, have you checked the network tab for the Payload of the request? Is it OK?

like image 147
mgonto Avatar answered Sep 20 '22 02:09

mgonto