Getting error when trying to delete record from hasMany collection - ember.js

ember-data#2.5.3
ember#2.4.3
I am getting the following error "Cannot set property 'jqXHR' of undefined" when attempting to delete a record. The item has already been deleted via model.deleteRecord, I am now trying to persist it to the server. I have tried this with both item.save() and item.destroyRecord() any ideas of what this message means? The request never actually reaches the server.

This is caused by a bug in v0.1.0 of the ember-data-has-many-query addon, which was fixed in v0.1.1. Updating to the latest version should fix it.

Related

EmberJS: Cannot read property '_application' of undefined

I'm working through the emberJS tutorial and every time I update the code it crashes with the following error:
Uncaught TypeError: Cannot read property '_application' of undefined
at appStarted (<anonymous>:9601:45)
at Object.initialize (<anonymous>:9721:11)
at index.js:136
at Vertices.each (dag-map.js:231)
at Vertices.walk (dag-map.js:145)
at DAG.each (dag-map.js:75)
at DAG.topsort (dag-map.js:83)
at App._runInitializer (index.js:151)
at App.runInstanceInitializers (index.js:134)
at Class._bootSync (instance.js:111)
The only way to get rid of it is to keep restarting the server. Any idea what is going on?
The solution was to stop using Ember Inspector

Redmine_RE plugin is not saving the data

i am using the Redmine.3.1.0.Then i have installed redmine_re plugin.But when i try to save the requirement using the Redmine_re plugin i am getting the following error
NameError (undefined local variable or method `connection' for #<ReArtifactRelationship:0x800ddb0>):
lib/plugins/acts_as_list/lib/active_record/acts/list.rb:220:in `bottom_item'
lib/plugins/acts_as_list/lib/active_record/acts/list.rb:214:in `bottom_position_in_list'
lib/plugins/acts_as_list/lib/active_record/acts/list.rb:205:in `add_to_list_bottom'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
pls suggest how to resolve this error
#ste26054
I did not develop this plugin, but I think the support for redmine 3.1.0 is only partial at the moment. (And you may get other errors even after fixing this).
I believe you are getting an error because of this: Deprecate #connection in favour of accessing it via the class
And your error is related to this file:
In this method:
def scope_condition()
"#{connection.quote_column_name("source_id")} = #{quote_value(self.source_id)}
AND
#{connection.quote_column_name("relation_type")} = #{quote_value(self.relation_type)}"
end
Try to add self.class. in front of connection
You may have to repeat this for other files in the code.
If your changes are working, I would suggest you to submit a pull request on their plugin github page :)

Use Ember.set() to set the 'content' property

We have an issue that seems to be very similar to https://github.com/emberjs/ember.js/pull/9767. The error we get is the following:
Error while processing route: [route-name] Assertion Failed: You must use Ember.set() to set the 'content' property (of [route]) to 'undefined'.
So the only difference is that it complaints about 'content' instead of 'controller', and that it is trying to set it to 'undefined'. This only happens for a few users, and it seems to be mostly old Android-devices. We have managed to reproduce the error in the default browser on a device running android 2.3.4.
Does anyone have a clue to why this happens? Debugging on old android devices is a pain!
I forgot about this question on StackOverflow, and someone else in our team have committed a fix for the issue. This line of code:
return self.getJSON(self.get('dataUrl'))
.then(self.get('_modelMap').bind(self))
Have been changed to this:
return self.getJSON(self.get('dataUrl'))
.then(function(data) {
return self._modelMap(data);
})
This was done in one of our base controllers.
Handlebars was also upgraded from v1.3.0 to v2.0.0 in the same commit. Don't know if that is required for fixing the issue though.
Hopefully this can help others with the same issue :)

How to deal with possible duplicates in an Ember store?

My Ember apps retrieves model objects from an API that can contain duplicates on successive calls.
I want to store my objects like this:
myController.store.createRecord('myModel', myModelObject).save()
Unfortunately, when a duplicate occurs, I get the following error in the console:
Error: Assertion Failed: The id XXX has already been used with another record of type MyApp.MyModel.
(fonction anonyme)ember.js:3866
I couldn't figure a way to recover gracefully from that error. I tried:
myController.store.createRecord('myModel', myModelObject).save().catch(myFailureCallback)
but the failure callback doesn't get called and the error is the same.
You could check to see if the record is already loaded into the store
http://emberjs.com/api/data/classes/DS.Store.html#method_recordIsLoaded
store.recordIsLoaded('myModel', myModelObject.get('id'))

Getting "Error: Assertion Failed: calling set on destroyed object" when trying to rollback a deletion

I am looking into how to show proper deletion error message in ember when there is an error coming back from the server. I looked at this topic and followed its suggestion:
Ember Data delete fails, how to rollback
My code is just like it, I return a 400 and my catch fires and logs, but nothing happens, when I pause it in the debugger though and try to rollback, I get Error: Assertion Failed: calling set on destroyed object
So A) I cannot rollback B) the error is eaten normally.
Here is my code
visitor.destroyRecord().then(function() {
console.log('SUCCESS');
}).catch(function(response) {
console.log('failed to remove', response);
visitor.rollback();
});
In case it's relevant, my model does have multiple relationships. What am I doing wrong? Ember-data version is 1.0.0.8 beta (previous one from the release a few days ago).
Thanks in advance.
EDIT
I discovered now that the record actually is restored currently inside the cache according to ember inspector, but the object will not reappear in the rendering of the visitors. I need some way to force it to reload into the template...
After destroyRecord, the record is gone and the deletion cannot be rolled back. The catch clause will just catch a server error. If you want the record back, and think it's still on the server, you'll have to reload it.
See the following comment on deleteRecord from the Ember Data source:
Marks the record as deleted but does not save it. You must call
`save` afterwards if you want to persist it. You might use this
method if you want to allow the user to still `rollback()` a
delete after it was made.
This implies that a rollback after save is not possible. There is also no sign anywhere I can see in the Ember Data code for somehow reverting a record deletion when the DELETE request fails.
In theory you might be able to muck with the isDeleted flag, or override various internal hooks, but I'd recommend against that unless you really know how things work.
Try reloading the model after the rollback. It will reload from the server but it was the only way around this that I could find.
visitor.destroyRecord().then(function() {
console.log('SUCCESS');
}).catch(function(response) {
console.log('failed to remove', response);
visitor.rollback();
visitor.reload().then(function(vis)
{
console.log('visitor.reload :: ' + JSON.stringify(vis));
});
});
Hope that helps.