ampersand-state icon indicating copy to clipboard operation
ampersand-state copied to clipboard

Extend docs, how to manage object/collection associations with non-nested resources

Open elisechant opened this issue 8 years ago • 4 comments

Given a resource with the following format:

var connection = {id:1, messages_id:[1,2,3]};

var messages = [
    {id:1, description: 'messagecontent'},
    {id:2, description: 'second messagecontent'},
    {id:3, description: 'third messagecontent'}
];

In addition to http://ampersandjs.com/learn/state#handling-relationships-between-objectsmodels-with-derived-properties, provide an example of how to manage model/collection associations with non nested resources, which imitates the behaviour of nested resources:

var connection = {id:1, messages:[
    {id:1, description: 'messagecontent'},
    {id:2, description: 'second messagecontent'},
    {id:3, description: 'third messagecontent'}
]};

MessageModel = State.extend({
    props: 'id',
    description: 'string'
});
MessagesCollection = Collection.extend({
    collections: {
        messages: MessageModel
    }
});

elisechant avatar Jul 28 '15 20:07 elisechant

Am I correct in stating that a simplified version of your problem statement is "I didn't know about collections. per reading the docs, I feel like I should have sooner"?

cdaringe avatar Jul 29 '15 02:07 cdaringe

No, I think the description is quite clear

elisechant avatar Jul 29 '15 19:07 elisechant

sorry if tone was mis-conveyed. i ask only such that we could find a bit more of human readable approach to update the docs. i'm not confident that manage conveys enough purpose, or if the over-arching issue is clear enough. respectfully, maybe you can mock up how you feel it should updated to help improve clarity?

cdaringe avatar Jul 29 '15 21:07 cdaringe

@elisechant, is your question regarding how to model the Connection such that you can emulate a relation from message_ids to Message models in the MessagesCollection?

aaronmccall avatar Dec 03 '15 22:12 aaronmccall