Skip to content

Instantly share code, notes, and snippets.

@foxnewsnetwork
Created March 23, 2015 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxnewsnetwork/a87092819f8d268f2ab3 to your computer and use it in GitHub Desktop.
Save foxnewsnetwork/a87092819f8d268f2ab3 to your computer and use it in GitHub Desktop.
Ember data models in nested dir

Often, in big Ember projects where you have a lot of models, it makes sense to put model files into their own directories.

For example, instead of:

app
  -- models
    -- dog.js
    -- cat.js
    -- bat.js
    -- candidate.js
    -- offer.js
    -- answer.js

it makes sense to namespace:

app
  -- models
    -- ephermal
      -- candidate.js
      -- offer.js
      -- answer.js
    -- persistent
      -- dog.js
      -- cat.js
      -- bat.js

But how do you get your application store to correctly resolve your organized models? The Ember guys didn't document this because they probably thought the solution is obvious (it wasn't to me): you use the "/".

store.find "ephermal/candidate"
store.find "persistent/dog"

container.resolve "model:ephermal/offer" # resolves to your model, a subclass of DS.Model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment