Skip to content

Save on newly restangularized object results in undefined route #1179

@dsollen

Description

@dsollen

The name says it all. When a save is done on a newly created restangularizedElement it's route is always null. For example:

var newRestObject = Restangular.restangularizeElement(null, {}, 'foo'};
newRestObject.save().then( function(result) {
     log("route "+result.route);
     log("parentRoute "+result.parentResource.route);
 });

will result in the print out:

route undefined
parentRoute foo

I would instead expect the route to be 'foo' with a null parentResource. This is not limited just to new RestangularizedObjects. I believe that

newRestObject = Restangular.one('foo')

would have the same problem, and I believe I saw it in another use case but can't find it currently.

This is an issue for us because we have a number of controllers that expect a Restangular element or collection to be passed to them. Our modules will occasional pass an empty restangularizedElement when no element yet exists. After we call save on the new element we are unable to do anything with the returned element due to the bad route. It also fails to run any of the 'foo' transformation hooks we would have expected, which is a problem due to our installing a multitude of methods via such hooks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions