1. #1
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default Unanswered: Properly destroy extended instances

    Unanswered: 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The model instance should have a destroy() method.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      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.

Thread Participants: 1