Extjs 5 data model - has many associations

I am trying to understand the concept of a new association in Extjs 5 data models.

I have the following models

// User Ext.define('App.model.User', { extend: 'App.model.Base', fields: [ {name: 'id', type: 'string'}, {name: 'name', type: 'string'}, ], manyToMany: { Categories: { type: 'Categories', role: 'categories', field: 'categories', right: true } } }); // Category Ext.define('App.model.Category', { extend: 'App.model.Base', constructor: function () {...}, fields: [ {name: 'id', type: 'string'}, {name: 'categoryName', type: 'string'}, ] }); 

I have the following json for the user:

  { "user": { "id": "1", "name": "Foo", "categories": [1, 2, 3] } } 

When the User model loads, it must initialize the category store with data.

(My Category model knows how to convert a number to an id object and categoryName)

For some reason, when I try to get user categories, the store is empty.

 userRecord.categories(); // has no records 

How can I make this work?

+6
source share
1 answer

Please, try

//User

 Ext.define('User', { extend: 'app.data.Model', fields: [ {name: 'id', type: 'string'}, {name: 'name', type: 'string'}, ], hasMany: { Categories: { type: 'Categories', role: 'categories', field: 'categories', right: true } } }); 
+1
source

Source: https://habr.com/ru/post/977334/


All Articles