Results 1 to 3 of 3

Thread: Properly destroy extended instances

  1. #1
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    623
    Answers
    67
    Vote Rating
    29
      0  

    Default Properly destroy extended instances

    I have some trouble with models and controllers after destroying them. Custom members seam to be there on every other instance.

    For example, if I have a model:

    Code:
    Ext.define('MyApp.model.Payment',{
        extend:'Ext.data.Model' ,
        config:{
            beneficiary:null,
            account:null,
            currency:null,
            remaining:null,
            category:null,
            details:null,
            fields:[
            {
                name: "creditorAccount",
                type: "string"
            },
    
    
            {
                name: "debtorAccount",
                type: "string"
            },
    
    
            {
                name: "amount",
                type: "number"
            },
    
    
            {
                name: "details"
                
            },
    
    
            {
                name: "category",
                type: "string"
            },
            ],
            validations:[
            {
                type: 'presence',
                field: 'creditorAccount'
            },
    
    
            {
                type: 'presence',
                field: 'amount'
            },
    
    
            {
                type: 'presence',
                field: 'debtorAccount'
            }
            ]
        }
    });
    First instance of this model type will not have any references to beneficiary, account, and the others. But if I set them, and then destroy the instance, all the future instances of this model will already have some references to these members (named _beneficiary, _account, etc) though they are fresh new instances and I would expect them to be empty as the first one.

    ( Also there is a bug on the framework, I think, destroying a model makes its private member named `modified` null, and this will cause an error on a new instance of this type, because there is a object expected in that member. )

    I had overwrite the destroy method for the model, to manually set my custom members to null, that is not enough it seams, the '_' underscore references are still there.

    So, how do you properly destroy a (model) instance?

    Thanks!

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    The model instance should have a destroy() method.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    623
    Answers
    67
    Vote Rating
    29
      0  

    Default

    As I said, it has a destroy method...




    Code:
    Ext.define('MyApp.model.Payment',{
        extend:'Ext.data.Model' ,
        config:{
            beneficiary:null,
            account:null,
            currency:null,
            remaining:null,
            category:null,
            details:null,
            fields:[
            {
                name: "creditorAccount",
                type: "string"
            },
    
    
            {
                name: "debtorAccount",
                type: "string"
            },
    
    
            {
                name: "amount",
                type: "number"
            },
    
    
            {
                name: "details"
                
            },
    
    
            {
                name: "category",
                type: "string"
            },
            ],
            validations:[
            {
                type: 'presence',
                field: 'creditorAccount'
            },
    
    
            {
                type: 'presence',
                field: 'amount'
            },
    
    
            {
                type: 'presence',
                field: 'debtorAccount'
            }
            ]
        },
     
        destroy:function()
        {
            this.setBeneficiary(null);
            this.setAccount(null);
            this.setCurrency(null);
            this.setRemaining(null);
            this.setCategory(null);
            this.setDetails(null);
            this.callParent(arguments);
            this.modified= {};
        }
    });
    First instance has data and _data an everything a model normally has, every other instances receive some _my_defined_members also.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •