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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With