ember-data-model-fragments icon indicating copy to clipboard operation
ember-data-model-fragments copied to clipboard

5.0.0-beta.0 - You should not change the <type> of a RecordIdentifier

Open mpirio opened this issue 4 years ago • 3 comments

Hello,

We have updated your application to Ember 3.15 and also updated ember-data-model-fragments to 5.0.0-beta.0.

Unfortunately, when loading one of our views, we have the following error message in our web console :

vendor.js:243639 Uncaught Error: You should not change the <type> of a RecordIdentifier
    at IdentifierCache._getRecordIdentifier (vendor.js:243639)
    at IdentifierCache.getOrCreateRecordIdentifier (vendor.js:243693)
    at InternalModelFactory.lookup (vendor.js:249109)
    at InternalModelFactory.getByResource (vendor.js:249146)
    at Class._internalModelForResource (vendor.js:252904)
    at Class.createFragment (vendor.js:267614)
    at createFragment (vendor.js:267978)
    at vendor.js:266813
    at Array.map (<anonymous>)
    at normalizeFragmentArray (vendor.js:266786)

We found where the problem came from: our model has a "fragmentArray" attribut of type "billingDetail". This fragment model is defined in the file "models/billing-detail.js". When we change type "billingDetail" to "billing-detail", all works! If we return to "billingDetail", the error come again... Before upgrade, it worked.

We did not change the type in our code, juste display the content of this "fragmentArray" attribut. What do you think about? Thanks,

mpirio avatar Jun 23 '20 20:06 mpirio

I believe this will have been a change within Ember Data itself and not model fragments specifically. The recommended pattern is that you use hyphen-case when referencing your models. Take this from the public Ember Data guides

modelName convention By convention, the name of a given model (its type) matches the name of the file in the app/models folder and should be lowercase, singular and dasherized.

patocallaghan avatar Nov 09 '20 22:11 patocallaghan

Should the file name be changed in this case, esp when you cannot change the representation in the code?

knownasilya avatar Nov 10 '20 18:11 knownasilya

I had a similar problem with ember-data 3.13.3. In my case it was a polymorphic type coming back from my API as snake_case. Changing to kebab-case fixed it. I think the fallback for E-D [3.13,3.15) doesn't normalize the type, since it's working after I upgraded ember-data.

https://github.com/adopted-ember-addons/ember-data-model-fragments/blob/3eeccc23e26ba1e7152548d62560c20361af1cbb/addon/ext.js#L124-L131

dwickern avatar Jan 19 '21 02:01 dwickern