from the previus post
http://www.sencha.com/forum/showthre...ocs)-problem-2

this applies to Extjs 4.1 beta 1 beta 2 and beta 3 source code.
(having the correct concept of has one) “Has one” setter should take the given id and set the associated model id with this value, since the forerign key is in the associated model, not as “belongs to” where the foreign is in the owner model.
Heres a test case to check the errors.

these models represent person (per model ) and user account (usr model)
associations are "person has one user account" and "user account belongs to a person"
Code:
    
    Ext.define('per', {
        extend: 'Ext.data.Model',
        fields: [
            {name:'perId'    ,type:'int'}
        ],
        hasOne:[
            {model:'usr',    associationKey:'usr',    primaryKey:'perId',    foreignKey:'perId',     getterName:'usr',    setterName:'usrSet'}
        ],
        idProperty: 'perId'
    });
    
    Ext.define('usr', {
        extend: 'Ext.data.Model',
        fields: [
            {name:'usrId'    ,type:'int'},
            {name:'perId'    ,type:'int'},
        ],
        belongsTo:[
            {model:'per',    associationKey:'per',    primaryKey:'perId',    foreignKey:'perId',    getterName:'per',    setterName:'perSet'}
        ],
        idProperty: 'usrId'
    });
first testing belongsTo association (belongsTo source code is fine) just to check if i models are working as expected
Code:
  
   // Testing belongsTo id propagation
    var per = Ext.create('per',{perId : 4});
    var usr = Ext.create('usr',{usrId : 7});
    usr.perSet(per); // appending per to usr should set usr.perId to 4
    console.log('BelongsTo test');
    console.log(per.data); // nothing has changed, which is correct.
    console.log(usr.data); // usr.perId now its 7, which is correct.
Evething went well with belongsTo, so models are well definided. Now checking hasOne, wich i know it has errors.
Code:
    
    // Testing hasOne id propagation    
    var per = Ext.create('per',{perId : 4});
    var usr = Ext.create('usr',{usrId : 7});
    per.usrSet(usr); // appending usr to per should set usr.perId to 4
    console.log('HasOne test');
    console.log(per.data); // per.perId now its 7, copied the usr.usrId to per.perId as an expected error.
    console.log(usr.data); // nothing has changed, usr.perId wasnt set
the source code with problems and the fix.
this code is from the source of HasOne association (red comments are mine)
Code:
createSetter: function() {
        var me              = this,
            ownerModel      = me.ownerModel, // unused var ?
            foreignKey      = me.foreignKey;
        //'this' refers to the Model instance inside this function
        return function(value, options, scope) {
            // wrong code start -----------------------------------------------------------
            if (value && value.isModel) { //value shouldnt optionally be a model, always must be a model.
                value = value.getId(); 
            }
            this.set(foreignKey, value); // shouldnt set a value to "this" model
                                         //  the id should propagate from "this" model
                                         //  to the associated model (passed as first parameter "value")
                                         // thats the conceptual meaning of "hasOne"
            // wrong code end -----------------------------------------------------------
            if (Ext.isFunction(options)) {options = {callback: options,scope: scope || this};}
            if (Ext.isObject(options)) {return this.save(options);}
          };
    },
the fix
Code:
    createSetter: function() {
        var me              = this,
            ownerModel      = me.ownerModel,
            foreignKey      = me.foreignKey;
        //'this' refers to the Model instance inside this function
        return function(value, options, scope) {
            
            value.set(foreignKey,this.getId()); // value must be always a model
                                                // this line should replace the wrong code
            
            if (Ext.isFunction(options)) { options = {callback: options,scope: scope || this};}
           if (Ext.isObject(options)) { return this.save(options);}
       };
    },