Skip to content

fix: register data models under their camelCase record type - #464

Open
herzzanu wants to merge 1 commit into
orbitjs:mainfrom
herzzanu:fix-kebab-case-model-names
Open

fix: register data models under their camelCase record type#464
herzzanu wants to merge 1 commit into
orbitjs:mainfrom
herzzanu:fix-kebab-case-model-names

Conversation

@herzzanu

@herzzanu herzzanu commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #463.

Model files are kebab-case on disk, so setupOrbit receives glob keys like ../data-models/planetary-system.ts and registers the model under planetary-system. Both consumers of registrations.models look models up by camelCase record type instead, so every multi-word model is unreachable:

  • DataSchema builds its model map from getRegisteredModels(), which camelized the keys and then indexed the un-camelized registry — the lookup returns undefined and destructuring throws during setupOrbit.
  • Cache#modelFactoryFor(type) is called with the record type, so it hits the same mismatch and asserts "An ember-orbit model for type … has not been registered."

The change

Camelize once at registration, and let getRegisteredModels() return the keys as stored, so registration and lookup agree. Registry keys now match the record types used everywhere else, which is also what modelFactoryFor already assumed.

The alternative — keeping the registry kebab-cased and camelizing only the schema's model names — would leave modelFactoryFor needing its own conversion, so normalizing at the single write point seemed cleaner. Happy to switch if you'd prefer it the other way.

Why the existing suite didn't catch this

Both paths that register models avoid real kebab-case file names:

  • Integration tests go through tests/support/store.ts#createStore, which synthesizes module keys from the dict keys the test passes — and those are already camelCase (binaryStar, planetarySystem).
  • The test app's route globs a real folder, but tests/test-app/data-models/ only contains moon.ts and planet.ts, and camelize('moon') === 'moon'.

The added test closes that gap by registering a fixture under a kebab-case key, the way a real glob would.

Verification

Run against this repo's suite (Chrome; Firefox isn't installed locally):

  • Without the source change, with the new test present: 172 passed, 2 failed, both with TypeError: Cannot destructure property 'keys' of 'orbitRegistry.registrations.models[name]' as it is undefined
  • With the source change: 174/174 passed

prettier --check, eslint and tsc --noEmit are clean.

I also hit this on a classic ember-cli app (via ember-classic-import-meta-glob), where it prevented boot entirely; the failing test here runs through the Vite build, so it isn't builder-specific.

Model files are kebab-case on disk, so setupOrbit received keys like
'../data-models/planetary-system.ts' and registered the model as
'planetary-system'. Both consumers of registrations.models look models up
by camelCase record type instead:

- DataSchema builds its model map from getRegisteredModels(), which
  camelized the keys before indexing the un-camelized registry, so the
  lookup returned undefined and destructuring threw during setupOrbit.
- Cache#modelFactoryFor(type) is called with the record type, so it hit
  the same mismatch.

Camelize once at registration and let getRegisteredModels return the keys
as stored, so registration and lookup agree.

Single-word names were unaffected, which is why the existing suite passed:
tests supply already-camelCase keys to createStore, and the test app's
data-models folder only holds moon.ts and planet.ts.
@herzzanu

herzzanu commented Aug 5, 2026

Copy link
Copy Markdown
Author

@RobbieTheWagner @NullVoxPopuli — small fix with a red/green test, would appreciate a look when you have a moment.
@lucacorti this may also cover the schema errors you hit in #431, if you're still on this path.

@lucacorti

Copy link
Copy Markdown

@herzzanu with this I get a build error:

ERROR in ../../../../../../private/var/folders/f7/4l5jd79d4zd4pf_rym3xbyzw0000gn/T/broccoli--69261-1r71sqhed9o9/cache-207-webpack_bundler_ember_auto_import_webpack/app.cjs 119:124-146
Module not found: Error: Package path . is exported from package /private/var/folders/f7/4l5jd79d4zd4pf_rym3xbyzw0000gn/T/broccoli--69261-1r71sqhed9o9/cache-207-webpack_bundler_ember_auto_import_webpack/node_modules/ember-orbit, but no valid target file was found (see exports field in /private/var/folders/f7/4l5jd79d4zd4pf_rym3xbyzw0000gn/T/broccoli--69261-1r71sqhed9o9/cache-207-webpack_bundler_ember_auto_import_webpack/node_modules/ember-orbit/package.json)

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

Successfully merging this pull request may close these issues.

Multi-word model names are never found: models register kebab-case but the schema looks them up camelized

2 participants