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

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

Open
mpirio opened this issue Jun 23, 2020 · 3 comments
Open

Comments

@mpirio
Copy link

mpirio commented Jun 23, 2020

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,

@patocallaghan
Copy link
Contributor

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.

@knownasilya
Copy link
Collaborator

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

@dwickern
Copy link
Contributor

dwickern commented Jan 19, 2021

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.

if (lte('ember-data', '3.13.0')) {
throw new Error('This version of Ember Data Model Fragments is incompatible with Ember Data Versions below 3.13. See matrix at https://github.com/lytics/ember-data-model-fragments#compatibility for details.');
}
if (gte('ember-data', '3.15.0')) {
identifier = this.identifierCache.getOrCreateRecordIdentifier({ type, id, lid });
} else {
identifier = { type, id, clientId: lid };
}

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

4 participants