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

Best(?) practice for loading & saving relational data #1008

Closed
timblack1 opened this issue Dec 8, 2014 · 2 comments
Closed

Best(?) practice for loading & saving relational data #1008

timblack1 opened this issue Dec 8, 2014 · 2 comments

Comments

@timblack1
Copy link

What is the best, or just a good, practice for loading and saving relational data in Polymer elements' published properties?

I've used https://github.com/PaulUithol/Backbone-relational to load and save relational data. It depends on Backbone. But now with Polymer's use of Object.observe(), I mostly don't need Backbone's complex model objects (at least I don't need their get() and set() methods), but I can't figure out how I can best get rid of Backbone's complex model objects and just use plain JavaScript objects AND load and save relational data to my data store.

Is there a Polymer-compatible library/web component out there which already implements this? Or a native way to do it?

Here are a couple ways I could do it myself without a library, but I expect I'm missing lots of edge cases.

1.  Load relational data:

// Load from server
model = store.get('model-id');
// model == {'id':'abc', 'name':'Parent', child_ids:['child-id1', 'child-id2']}
for (child_id in model.child_ids){
    model.children[child_id] = store.get(child_id);
}
// Use model in Polymer element's published property here

2.  Save relational data:

// Get model from Polymer published property here
model.child_ids = [];
for (child in model.children){
    model.child_ids.push(child.id);
}
delete model.children;
store.set(JSON.stringify(model));
// or just store.set(model);
@ebidel
Copy link
Contributor

ebidel commented Dec 8, 2014

Hey @timblack1, you may want to ask this question on StackOverflow as it's not a bug or feature request for Polymer.

@timblack1
Copy link
Author

@ebidel You're right; sorry about that.

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

No branches or pull requests

2 participants