Hi,
(This may sound odd, and I’ll be happy to hear a different approach for achieving what I need…)
I have a route, let say /post/:post_id.
In this route there is an operation to “clone” the current post. This operation sends request to the server, which duplicates the post and returns the newly created post-id.
Now I want to transition to this post.
I could just:
this.transitionTo('post', newPostId)
but this seems too expensive operation for just transitioning to a cloned post (as it will cause another trip to the server, and also cause all computed properties, etc to be recalculated).
I’m trying to optimize this by replacing the id of the original post:
thePost = this.modelFor('post');
thePost.set('id', <the new id from server>);
this.transitionTo('post', thePost)
but this doesn’t seem to update the url…
any advice?
That doesn’t make sense. You can’t just change the id and expect it to be a different model.
Just use the transitionTo. Pass in the post if you don’t want the model hook to be called.
Thanks.
My problem is though my “post” model is pretty big.
And so my “clone” operation does not return the full model but rather just the new ID.
So I want to avoid the second call to the server and also all re-calculations of computed property because of a model change.
I would avoid doing that, even if you could find a hacky way to make it work, I wouldn’t feel confident it would be robust if you intend to update Ember/Ember-Data later.
I think of the ID like a primary key in SQL, you can’t just reassign it as it is the only part of each record that is immutable by design.
Could you not just get the new ID, loop each property in your model and push the value from the old ID into the new one? Then you can transitionTo without needing to make a request to your server?
I can do that - cloning the entire model.
And I can transition without calling the server this way.
I would still get all my computed properties re-calculated (unless I refactor those too somehow…). These calculations are very heavy in my case.
Could you not check if the record is loaded and use peekRecord instead if findRecord , that might stop the server return at least ?