Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
elisechant opened this issue Jul 28, 2015 · 4 comments

Comments

@elisechant
Copy link

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
    }
});
@cdaringe
Copy link
Member

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"?

@elisechant
Copy link
Author

No, I think the description is quite clear

@cdaringe
Copy link
Member

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?

@aaronmccall
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants