adopted-ember-addons / adopted-ember-addons/ember-data-model-fragments
Relationships within a fragment
- 主要語言
- TypeScript
- 星號
- 367
- 分支
- 108
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Great work on the fragments library so far; I've found it very helpful in upgrading from the old Ember Data to the new 1.0 Beta series.
However, I am wondering if we could re-enable relationships inside of fragments. There are several instances in my data-model where my fragments "point to" other models. Before, they would use a "belongsTo" relationship; but now that doesn't seem to work. I've found workarounds, but they haven't been seamless for all use-cases.
This is the scenario where I'm most frequently running into this issue:
A many-to-many relationship between models A and B where A has a list of fragments, C. C has the "belongsTo" relationship with B along with other fields that "describe" the relationship. B, meanwhile, doesn't know anything about A or C.
My current work-around looks like this:
``` CoffeeScript
App.Transaction = DS.Model.extend
purchases: DS.hasManyFragments 'purchase'
...
App.Purchase = DS.ModelFragment.extend
product_id: DS.attr 'string'
cost: DS.attr 'number'
quantity: DS.attr 'number'
product: (() ->
@store.find('product', @get('product_id'))
).property('product_id')
App.Product = DS.Model.extend
name: DS.attr 'string'
...
```
However, if Transaction needs to compute a property based on the Products' name (to list all products purchased, for instance), then I'm suddenly forced to implement a much more obscure work-around to get the Transaction's computed property to update in templates. I'm pretty sure that this is due to the fact that store.find returns a Promise.
If someone has a much better work-around to this issue, please let me know. Right now, it seems to me that allowing Fragments to have "belongsTo" relationships is the easiest way to correct the problem while keeping DS.ModelFragment's usage similar to DS.Model's current usage.
貢獻指南
評估
這個 Issue 還沒有評估資料。