2 * @example Lazy Associations
4 * This example demonstrates lazy loading of a {@link Ext.data.Model}'s associations only when requested.
5 * a `User` model is loaded, then a separate request is made for the `User`'s associated `Post`s
6 * See console for output.
9 // define the User model
11 extend: 'Ext.data.Model',
12 fields: ['id', 'name', 'age', 'gender'],
23 hasMany: 'Post' // shorthand for {model: 'Post', name: 'posts'}
26 //define the Post model
28 extend: 'Ext.data.Model',
29 fields: ['id', 'user_id', 'title', 'body'],
41 hasMany: {model: 'Comment', name: 'comments'}
44 //define the Comment model
45 Ext.define('Comment', {
46 extend: 'Ext.data.Model',
47 fields: ['id', 'post_id', 'name', 'message'],
52 Ext.require('Ext.data.Store');
53 Ext.onReady(function() {
54 // Loads User with ID 1 User's Proxy
56 success: function(user) {
57 console.log("User: " + user.get('name'));
59 // Loads posts for user 1 using Post's Proxy
61 callback: function(posts, operation) {
62 Ext.each(posts, function(post) {
63 console.log("Comments for post: " + post.get('title'));
65 post.comments().each(function(comment) {
66 console.log(comment.get('message'));