Skip to content

Instantly share code, notes, and snippets.

@noroot
Last active August 29, 2015 14:05
Show Gist options
  • Save noroot/7764926571bd466fc400 to your computer and use it in GitHub Desktop.
Save noroot/7764926571bd466fc400 to your computer and use it in GitHub Desktop.
ExtJS 5 assiciations
Ext.define('MyApp.model.User', {
extend: 'MyApp.model.Base',
fields: [{
name: 'name',
type: 'string'
}]
});
Ext.define('MyApp.model.Post', {
extend: 'MyApp.model.Base',
fields: [{
name: 'userId',
reference: 'User', // the entityName for MyApp.model.User
type: 'int'
}, {
name: 'title',
type: 'string'
}]
});
// Loads User with ID 1 and related posts and comments
// using User's Proxy
MyApp.model.User.load(1, {
callback: function(user) {
console.log('User: ' + user.get('name'));
user.posts(function(posts){
posts.each(function(post) {
console.log('Post: ' + post.get('title'));
});
});
}
});
user.posts().add({
userId: 1,
title: 'Post 10'
});
user.posts().sync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment