ampersand-state
ampersand-state copied to clipboard
Extend docs, how to manage object/collection associations with non-nested resources
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
}
});
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"?
No, I think the description is quite clear
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?
@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?