ember-data-model-fragments
ember-data-model-fragments copied to clipboard
Allow id in fragment
Hello,
I would request to allow a (optional) id field for the fragment. The reason for this request is, that it seams to be the most suitable clean solution to handle compositions with ember/JSONAPI. I started a discussion without much participation about this problem here: https://discuss.emberjs.com/t/ember-data-handling-composition/15035/2
When allowing fragments to have an id attribute, they would solve the problem of compositions without changes at JSONAPI and backend frameworks in a nice way.
I'm seeing this issues too (my fragment has a ID field that gets stripped during conversion from the wire to the framgment instance). First, adding an ID field explicitly fails with the standard ember error message about having an ID field on a model. But removing it, and relying on the underlying model's default ID field doesn't work either. It seems the specific problem is that the ID value is getting stripped out in the extractAttributes() method of the serializer, and so apparently never gets passed along to the fragment. Not sure whether avoiding this ID stripping with a custom serializer might work around the problem? If I have a chance to test, I'll come back to update
Hmm, it surprises me that there's no id. My experience with adopting this addon is this: I replaced a lot of code using ember data fragments, but many templates reference an ID explicitly. Is there a good reason for disallowing an identifier for this object? My instinct is that that seems like a bad practice.
The README on this issue is confusing as well: https://github.com/lytics/ember-data-model-fragments#conflict-resolution. Maybe it means that "id-less embedded records" being in ember data proper is an issue?
This thread adds some interesting context: https://github.com/lytics/ember-data-model-fragments/issues/86#issuecomment-149375719.
I think this assumes I shouldn't use an id directly for presentation purposes?