1. #1
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    103
    Vote Rating
    7
    abierbaum is on a distinguished road

      0  

    Question [OPEN-126] Model.destroy method doesn't exist

    I have been trying to follow along the Model documentation to test a RestProxy that supports GET, PUT, POST, DELETE. I got all the way up to delete, but I can't figure out how to delete a model item.

    I tried the example code from the Model class, but it says to call 'user.destroy()' (where user is a Model item).

    Problem is, it doesn't look to me like that method exists.

    Can anyone confirm how to delete a model item once it is created?

  2. #2
    Ext JS Premium Member
    Join Date
    Mar 2009
    Location
    San Mateo, CA
    Posts
    32
    Vote Rating
    4
    bergstyle is on a distinguished road

      0  

    Default

    you right abierbaum that method is missing right now. on the bright side it's a known issue and should make it into a point release soon. for now you'll have to grab the proxy and execute a delete operation on there instead.

  3. #3
    Sencha User
    Join Date
    Dec 2007
    Posts
    10
    Vote Rating
    0
    robmonie is on a distinguished road

      0  

    Default

    This still seems to be missing, or am I missing something ?

  4. #4
    Sencha User
    Join Date
    May 2011
    Posts
    3
    Vote Rating
    0
    seanlynch is on a distinguished road

      0  

    Default

    I ran into the same problem too. Seems crazy that no one caught this.

    Also, call destroy on the proxy is not a very helpful comment as well as you actually have to fake your own operation dictionary. The following code worked for me, YMMV:

    Code:
    this.myModel.getProxy().destroy(new Ext.data.Operation({action: 'destroy', id: this.myModel.getId()}));

  5. #5
    Ext Premium User
    Join Date
    Mar 2007
    Posts
    89
    Vote Rating
    1
    Luc is on a distinguished road

      0  

    Default

    I ran into the same issue: destroy on Model not implemented.

    You may use the following override (based on the save method), until it is fixed:

    Code:
    Ext.override(Ext.data.Model, {
            destroy: function (options) {
                var me = this,
                action = 'destroy';
    
                options = options || {};
    
                Ext.apply(options, {
                    records: [me],
                    action: action
                });
    
                var operation = new Ext.data.Operation(options),
                successFn = options.success,
                failureFn = options.failure,
                callbackFn = options.callback,
                scope = options.scope;
    
                var callback = function (operation) {
    
                    if (operation.wasSuccessful()) {
    
    
                        if (typeof successFn == 'function') {
                            successFn.call(scope, record, operation);
                        }
                    } else {
                        if (typeof failureFn == 'function') {
                            failureFn.call(scope, record, operation);
                        }
                    }
    
                    if (typeof callbackFn == 'function') {
                        callbackFn.call(scope, record, operation);
                    }
                };
    
                me.getProxy()[action](operation, callback, me);
    
                return me;
            }
        
        })

  6. #6
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,159
    Vote Rating
    7
    rdougan will become famous soon enough

      0  

    Default

    Thanks for the report. I have added this into our tracker.

  7. #7
    Sencha User
    Join Date
    Jul 2011
    Posts
    27
    Vote Rating
    0
    lpfx is on a distinguished road

      0  

    Default Return

    Luc... I'm using the override that you post for the detroy method, but I can get the return of the method (if it was successful or not).

    Does anyone know how to do this?

    Example:
    Code:
    rec.destroy({
          success : function() {
                 // something here (nothing happens here)
          },
          failure : function() {
                // something here (nothing happens here)
          }
    });

  8. #8
    Sencha User
    Join Date
    Aug 2011
    Posts
    13
    Vote Rating
    0
    juniorplenty is on a distinguished road

      0  

    Default Seriously?

    Is this seriously still an open issue (the "D" in "CRUD" missing?????) or is this entire thread missing something obvious? Anyway - I can confirm that the 1.1.1 docs don't match up with the actual code (standard) and that there's no way to delete a model in sencha 1.1.1. Which is still the active release. A full year after this bug was posted.

  9. #9
    Sencha Premium User
    Join Date
    Mar 2016
    Posts
    3
    Vote Rating
    0
    ShadowFoxish is on a distinguished road

      0  

    Default

    @ Post #5: This solution does not work.

Similar Threads

  1. [FIXED][3.2.1] Element.autoHeight() doesn´t exist
    By defcon1 in forum Ext 3.x: Bugs
    Replies: 2
    Last Post: 5 May 2010, 6:48 AM
  2. Suppress error when container element doesn't exist
    By knight in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 25 Jan 2008, 1:54 AM
  3. [Ext.BasicDialog].destroy(true) doesn't destroy shadow
    By diegovilar in forum Ext 1.x: Bugs
    Replies: 1
    Last Post: 25 Mar 2007, 12:42 PM

Thread Participants: 8