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
How to define fragment dynamically? #218
Comments
@gauravjain028 I'm sorry, but I don't think this is something we can support in this manner. There is a lot of additional setup that goes on behind the scenes to make this app work, not unlike |
this is what i'm doing // models/user.js
import Ember from 'ember';
import DS from 'ember-data';
import { fragment } from 'model-fragments/attributes';
export default DS.Model.extend({
project: DS.belongsTo('project', {inverse: 'user'}),
data: fragment('data', { defaultValue() { return {}; }}),
fixupDataAttrs: Ember.observer('project.keys.@each.label', function () {
var attrs = {};
this.get('project.keys').forEach(function (key) {
attrs[key.get('label')] = DS.attr(key.get('type'));
})
this.get('data').reopen(attrs);
})
}) However, my needs are different. My models must be generated lazily from a schema we grab from an XHR payload. They also can be backwards compatible. |
@bgerami that's an interesting approach. I'd say if it works for you go for it. I will caution you that you may have to tweak this solution over time. Using the runtime [observer] to modify the declarative definition seems like it could be a little brittle, say if ember-data chooses to restructure their internals. But a clever solution nonetheless. @gauravjain028 I'm going to close this issue because I believe two solutions have been offered here. If you think there is a bug here, or want to further discuss this, please reopen it. |
I want to use params as dynamic fragment, so i have created it as computed property. But it is not working. I have used like
But this give me error:
The text was updated successfully, but these errors were encountered: