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

Filter out ShimModelClass instances when running discoverEmberDataModels #2569

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

gilest
Copy link
Contributor

@gilest gilest commented Nov 29, 2023

Maybe a naive fix, but I was making a fork to try privately anyway 🤷🏻

Believe this will be a blocker to upgrading to v3 for any apps which have non-Model files in their app/models/ tree. This can be caused by addons so it's not always possible to resolve within an app without significant effort.

Fixes #2556

Ref:

@@ -11,5 +11,5 @@ export const hasEmberData =
@hide
*/
export function isDsModel(m) {
return m && typeof m.eachRelationship === 'function';
return m && typeof m.eachRelationship === 'function' && m.isModel === true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if isModel will be true for all classes we want to check

Comment on lines +1 to +10
// Mimics the static apis of ShimModelClass from ember-data
export default class Shim {
fields;
attributes;
relationshipsByName;

eachAttribute() {}
eachRelationship() {}
eachTransformedAttribute() {}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I add this file without the fix, this package's test suite fails
image

@gilest
Copy link
Contributor Author

gilest commented Jan 18, 2024

@SergeAstapov what are your thoughts on this fix? 🙂

gilest added a commit to gilest/ember-cli-mirage that referenced this pull request Jan 28, 2024
@gilest gilest changed the title Filter out shim model class when running discoverEmberDataModels Filter out ShimModelClass instances when running discoverEmberDataModels Jan 28, 2024
@chancancode
Copy link
Collaborator

FWIW, I ran into the same issue and applied the patch locally, and at least in my case, didn't run into issues (e.g. non-ED model brought by addons that happens to have a isModel property)

@SergeAstapov SergeAstapov merged commit 259505c into miragejs:master Feb 21, 2024
12 checks passed
@SergeAstapov
Copy link
Collaborator

Thank you @gilest!

@gilest gilest deleted the fix/filter-out-shim-model-class branch February 21, 2024 21:38
@gilest
Copy link
Contributor Author

gilest commented Feb 21, 2024

Please cut a release when you get a chance 🥺

@zeppelin
Copy link

@SergeAstapov This seems to fix the issue with model discoverability in out apps.
Could you please cut a release? 🙏

@SergeAstapov
Copy link
Collaborator

sorry for delays, this is published as v3.0.3. Thank you @gilest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discoverEmberDataModels crashes if there is a non ember-data object in the app/models folder
4 participants