Last active
August 29, 2015 14:05
-
-
Save noroot/7764926571bd466fc400 to your computer and use it in GitHub Desktop.
ExtJS 5 assiciations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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