Take the 2-minute tour ×

I've posted the same question to the Sencha forum: http://www.sencha.com/forum/showthread.php?259313-Dealing-with-nulls-in-nested-data&p=949429#post949429

I'm having trouble understanding how associations are supposed to work (in ExtJS 4.1.1a). Consider the following model:

Ext.define('FM.model.Project', {
    extend: 'Ext.data.Model',
    requires: ['FM.model.Company'],

    fields: [

    associations: [
        {type: 'belongsTo', model: 'FM.model.Company', associatedName: 'Customer'},
        {type: 'belongsTo', model: 'FM.model.Project', associatedName: 'Parent'},

Sometimes the "parent" or "customer" in the JSON data is null, in which case the association getter should return null as well. But instead, I get an exception:

Con is not a constructor

from ModelManager.js in create(). This happens because the BelongsTo association is trying to create a new instance with the associatedName (which is either "Parent" or "Customer"). This make zero sense to me.

How should I be handling such missing associations? Constructing a dummy new instance is not a good solution because I need to be able to tell if the associated data exists or not.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You're right, it should create a getter function that returns null.

Here's a work-around:

set the instanceName of the belongsTo relationship, and check if it exists before calling the getter:

{type: 'belongsTo', model: 'FM.model.Company', associatedName: 'Customer', instanceName:'customer'}



share|improve this answer

Your Answer


