Skip to content

Commit fee2996

Browse files
committed
Fixes mgonto#982
1 parent 7d5d5d7 commit fee2996

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/restangular.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,15 @@ module.provider('Restangular', function() {
11621162
if (elem) {
11631163

11641164
if (operation === 'post' && !__this[config.restangularFields.restangularCollection]) {
1165-
resolvePromise(deferred, response, restangularizeElem(__this, elem, what, true, null, fullParams), filledObject);
1165+
var data = restangularizeElem(
1166+
__this[config.restangularFields.parentResource],
1167+
elem,
1168+
route,
1169+
true,
1170+
null,
1171+
fullParams
1172+
);
1173+
resolvePromise(deferred, response, data, filledObject);
11661174
} else {
11671175
var data = restangularizeElem(
11681176
__this[config.restangularFields.parentResource],

test/restangularSpec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,21 @@ describe("Restangular", function() {
693693
$httpBackend.flush();
694694
});
695695

696+
it("Should keep route property when element is created", function() {
697+
var account1 = Restangular.restangularizeElement(null, {}, 'accounts');
698+
$httpBackend.expectPOST('/accounts');
699+
$httpBackend.expectPUT('/accounts/1');
700+
account1.name = "Hey";
701+
account1.save().then(function(accountFromServer) {
702+
accountFromServer.id = 1;
703+
console.log(accountFromServer);
704+
return accountFromServer.save();
705+
}).then(function(accountFromServer2) {
706+
expect(accountFromServer2.route).toBe(account1.route);
707+
});
708+
$httpBackend.flush()
709+
});
710+
696711
it("Should make RequestLess connections with one", function() {
697712
restangularAccount1.one("transactions", 1).get().then(function(transaction) {
698713
expect(Restangular.stripRestangular(transaction))

0 commit comments

Comments
 (0)