I am using a mongo based DB schema where I have list of ReferenceFields (ObjectIds).
So assume I have two models : User, Group
User Object :
{
"_id" : ObjectId("554ba2897fdd66239457fb33"),
"name" : "something"
}
Group Object :
{
"_id" : ObjectId("453490sdkjskldfjlskdjf"),
"name" : "group_name",
users : [ ObjectId("554ba2897fdd66239457fb33"), ObjectId("554ba28a7fdd66239457fb34") ]
}
ExtJS User Model
Ext.define('Group',{
extend: 'Ext.data.Model',
idProperty : 'id',
fields:[
{name:'group_id', type : 'string', mapping : '_id', persist : false},
{name:'name', type : 'string', mapping : 'name', persist : false}
],
hasMany : { model : 'User', foreignKey:'id' , name : 'users'}
});
The User Model:
Ext.define('User',{
extend: 'Ext.data.Model',
idProperty : 'id',
fields:[
{name:'id', type : 'string', mapping : '_id', persist : false},
{name: 'name', type: 'string'},
]
});
in EXTJS code when I access group.users();
Using the rest method in stores when I add associations to models by giving a foreign Key it fires a GET request to
/users?filter=[{"property":"group_id","value":"453490sdkjskldfjlskdjf","exactMatch":true}]
But this is MySQL kind of association.
How do I solve this to adapt to mongo style of associations?
SO I basically want this to happen. Right now when I call
groups.users().load()
it fires a GET request to the Users proxy with the filter params like this
/users?filter=[{"property":"group_id","value":"453490sdkjskldfjlskdjf","exactMatch":true}]
. But I don't have group_id in users! So it has to query the users proxy based on the ObjectId it finds inside the users attribute of the group object.
As this is very common in Document based DB, Is this possible by default ? Am I missing something ? Thanks.