Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default [CLOSED][B2] Creating a new models gone wrong!

    [CLOSED][B2] Creating a new models gone wrong!


    I think there is something going terrible wrong with Ext.ModelMgr.create

    Consider basic model:
    Code:
    Ext.regModel('Login', {
    fields: [
        {name: 'LoginUserId', type: 'string'},
        {name: 'Password', type: 'string'},
        {name: 'IsNew', type: 'boolean', defaultValue: true},
        {name: 'IsDeleted', type: 'boolean', defaultValue: false},
        {name: 'IsDirty', type: 'boolean', defaultValue: true} ],
    validations: [
        {type: 'length', field: 'LoginUserId', message: "Login must be between 4 and 254 characters", min: 4, max: 254},
        {type: 'length', field: 'Password', message: "Password must be between 4 and 40 characters", min: 4, max: 40} ]
    });
    And this create method:
    Code:
    var loginObj = Ext.ModelMgr.create({ }, 'Login');
    If I try and call loginObj.setProxy(...) it says it's undefined. It looks like tons of methods are missing like "validate" when I look at Firebug.

    I went to the most basic example... This is what I want to do:

    Code:
    Ext.define('Ext.ux.SmartModel', {     
        extend: 'Ext.data.Model',
    
        constructor: function ()
        {
            this.isContructing = true;
            Ext.data.Model.prototype.constructor.apply(this, arguments);
            this.isContructing = false;
        },
    
        "set": function (fieldName, value)
        {
            if (value)
            {
                Ext.data.Model.superclass.set.call(this, fieldName, value);
                if (!this.isContructing && fieldName != "IsDirty")
                Ext.data.Model.superclass.set.call(this, "IsDirty", this.dirty);
            }
            else
            {
                Ext.data.Model.superclass.set.call(this, fieldName);
            }
        }
    }); 
    
    
    Ext.define('Login', {
    extend: 'Ext.ux.SmartModel',
    
    fields: [
        {name: 'LoginUserId', type: 'string'},
        {name: 'Password', type: 'string'},
        {name: 'IsNew', type: 'boolean', defaultValue: true},
        {name: 'IsDeleted', type: 'boolean', defaultValue: false},
        {name: 'IsDirty', type: 'boolean', defaultValue: true} ],
    validations: [
        {type: 'length', field: 'LoginUserId', message: "Login must be between 4 and 254 characters", min: 4, max: 254},
        {type: 'length', field: 'Password', message: "Password must be between 4 and 40 characters", min: 4, max: 40} ]
    }); 
    
    
     var loginObj = Ext.ModelMgr.create({
       
        }, 'Login');
    
    
    loginObj.setProxy( new Ext.data.RestProxy({
           url: '/Account/Login',
           reader:{
                   type: 'json'
           },
           writer:{
                  type: 'json'
          } }));
    But things are going horrible wrong with the .create method. Things work if I do a .getModel(...) and then do a .setProxy and then do a load(...) from my server. I can even do a .save().

    I swear this was all working prior to beta 1. I know I was doing .setProxy, validate, etc on my models before this change. Could this be a regression?

    Anyway, I suppose it's possible I am doing inheritance wrong. But when I go back to just using the ModelMgr and go back to the basics it still does not work.

    Also I know regModel was deprecated in B1. So that's why I switched my models around to not use them. At least for defining the models. But for the life of me I still don't see how you can "create" an instance of a model without ModelMgr.... Or at least I could not get them to work.

    See my prior post on this: http://www.sencha.com/forum/showthre...light=setProxy

    Anyway, I am frustrated because I thought everything was fixed in the model and that's why I moved on to other things. Now that I am back to hooking my model into my login screen it's all just falling apart
    Last edited by wizkid; 12 Apr 2011 at 5:54 PM. Reason: Clarity

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,996
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    There's not really enough information to figure out what's going on, however:

    Code:
    Ext.require('Ext.data.Model');
    
    Ext.onReady(function(){
    
        Ext.define('Super', {
            extend: 'Ext.data.Model',
            fields: ['a']
        });
        
        Ext.define('Sub', {
            extend: 'Super',
            fields: ['b']
        });
        
        var rec = Ext.ModelMgr.create({
            a: 'foo',
            b: 'bar'
        }, 'Sub');
        
        console.log(rec.get('a'), rec.get('b'));
        
        rec.setProxy({
            type: 'ajax',
            url: 'url'
        });
        rec.save();
    });
    When I run this code, it prints 'foo', 'bar' and then makes a request to 'url' with the following payload:
    Code:
    {"a":"foo","b":"bar"}
    I'd suggest waiting for the next release.

    Also, it's kind off odd you'd call setProxy on a Model instance, as opposed to on the Model itself, but it still works.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    I thought I was fairly detailed... I re-worked my example to the very simply, mirroring yours, and I can confirm this is still a bug.

    Code:
    Ext.require('Ext.data.Model');
    
    Ext.onReady(function() 
    {
    Ext.define('Login', {
            extend: 'Ext.data.Model',
    fields: [
        {name: 'LoginUserId', type: 'string'},
        {name: 'Password', type: 'string'},
        {name: 'IsNew', type: 'boolean', defaultValue: true},
        {name: 'IsDeleted', type: 'boolean', defaultValue: false},
        {name: 'IsDirty', type: 'boolean', defaultValue: true} ],
    validations: [
        {type: 'length', field: 'LoginUserId', message: "Login must be between 4 and 254 characters", min: 4, max: 254},
        {type: 'length', field: 'Password', message: "Password must be between 4 and 40 characters", min: 4, max: 40} ]
    });
    
    var loginObj = Ext.ModelMgr.create({
       
        }, 'Login');
    
    loginObj.setProxy( new Ext.data.RestProxy({
           url: '/Account/Login',
           reader:{
                   type: 'json'
           },
           writer:{
                  type: 'json'
          } }));
    
    
    });
    I get an exception "loginObj.setProxy is not a function" from firebug.

    I have this in my head:
    Code:
    <script src="/Scripts/extjs/bootstrap.js" type="text/javascript">
    I have cleared my browser cache several times. I did upgrade to beta 2... I suppose I could re-try copying the code again.

    Again, the create method is doing something wrong. It's not just the setProxy that is missing. Also, validate is among others.

  4. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    Is it wrong to be creating a proxy and then setting on the Model instance?

    I can see a million different use cases for this. For me I auto generate all my ExtJs Models using reflection in C# server side. These models can then be placed into one script that I have access to through-out my application. Then depending on the context, or what web method I want to be used I can call setProxy. The model is more re-useable that way.

  5. #5
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    I re-read your post... Are you saying that you tested this on your latest development code and this is working? Or did you test this on B2? I only have access to B2 of course!

  6. #6
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,996
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Against the latest source, I can confirm the issue with B2.

    The reason I say it's strange to set it on a particular model instance is that it's much more common to share the same proxy for all records of the model, for example:

    Code:
    var rec1 = Ext.ModelManager.create({}, 'Foo');
    var rec2 = Ext.ModelManager.create({}, 'Foo');
    
    // Weird!
    rec1.setProxy();
    rec2.setProxy();
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  7. #7
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    Thanks for the information about beta 2...

    Anyway I see what you mean about setProxy. I was originally using getModel and setting setProxy on what comes back. For my examples I was just trying to distill it down to the simplest level. My understanding is getModel will return the prototye, and then doing .create() on that will allow me to have the same proxy for all instances?

    Basically, what I want to do, is have one model (without proxy) auto-generated on my server (then saved off). Then at compile time (on the server) I will include the model, basically as a string, and then tack on the Proxy after the fact depending on what proxy I need for a given screen and model. I suppose I could do a string replace directly to the model before I send it down. I just thought using getModel and setProxy was cleaner.

    I looked at the source and I believe that's what it is doing.

    Regardless, the bug (that is now fixed in a upcoming release) was affecting more than just .setProxy... For example .validate was missing.

    Thanks for your help!

  8. #8
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    I can confirm this is now fixed in B3! Thanks!

  9. #9
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,996
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Ok great!
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Similar Threads

  1. Wrong reference when creating objects from extended class
    By Oliver Specht in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 17 Feb 2011, 6:48 AM
  2. [CLOSED] creating tpl format in new version 0.99 not working
    By avishek1 in forum Sencha Touch 1.x: Bugs
    Replies: 2
    Last Post: 9 Nov 2010, 10:02 AM
  3. models inside models
    By kortovos in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 27 Sep 2010, 3:43 AM
  4. SQLiteStore creating column wrong?
    By mitchellsimoens in forum Ext.air for Adobe AIR
    Replies: 1
    Last Post: 16 May 2010, 5:43 PM
  5. Replies: 1
    Last Post: 22 Dec 2009, 7:12 AM

Thread Participants: 1