{"action":"created","issue":{"url":"https://api.github.com/repos/emberjs/data/issues/2928","labels_url":"https://api.github.com/repos/emberjs/data/issues/2928/labels{/name}","comments_url":"https://api.github.com/repos/emberjs/data/issues/2928/comments","events_url":"https://api.github.com/repos/emberjs/data/issues/2928/events","html_url":"https://github.com/emberjs/data/issues/2928","id":63818783,"number":2928,"title":"[suggestion] store.adapterFor should progressively fallback on adapters instead of jumping to ApplicationAdapter when [modelName]Adapter isn't found","user":{"login":"foxnewsnetwork","id":1010423,"avatar_url":"https://avatars.githubusercontent.com/u/1010423?v=3","gravatar_id":"","url":"https://api.github.com/users/foxnewsnetwork","html_url":"https://github.com/foxnewsnetwork","followers_url":"https://api.github.com/users/foxnewsnetwork/followers","following_url":"https://api.github.com/users/foxnewsnetwork/following{/other_user}","gists_url":"https://api.github.com/users/foxnewsnetwork/gists{/gist_id}","starred_url":"https://api.github.com/users/foxnewsnetwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foxnewsnetwork/subscriptions","organizations_url":"https://api.github.com/users/foxnewsnetwork/orgs","repos_url":"https://api.github.com/users/foxnewsnetwork/repos","events_url":"https://api.github.com/users/foxnewsnetwork/events{/privacy}","received_events_url":"https://api.github.com/users/foxnewsnetwork/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-23T20:00:31Z","updated_at":"2015-03-23T20:36:00Z","closed_at":null,"body":"Suppose I have the following app structure:\r\n\r\n```bash\r\napp\r\n  ...\r\n  -- adapters\r\n    -- fires.js\r\n    -- rails.js\r\n    -- application.js\r\n  -- models\r\n    -- fires\r\n      -- icecandidate.js\r\n      -- offer.js\r\n      -- answer.js\r\n      -- session.js\r\n    -- rails\r\n      -- user.js\r\n      -- dog.js\r\n      -- cat.js\r\n      -- mom.js\r\n  ...\r\n```\r\n\r\nRight now, we have:\r\n\r\n``` coffeescript\r\ntype = container.lookupFactory \"model:fires/offer\"\r\nstore.adapterFor type \r\n# Gets me ApplicationAdapter since I don't have a fires/offer adapter\r\n```\r\n\r\nSo, if I want all my models in the models/fires directory to use the FiresAdapter, I have no choice but to submit to the humiliation of making an adapter for all of them in adapter/fires... Instead, can we get:\r\n\r\n```livescript\r\ntype = container.lookupFactory \"model:fires/offer\"\r\nstore.adapterFor type \r\n# Gets me FiresAdapter\r\n```\r\n\r\nAll that needs to be done for this is to change the following from:\r\n```javascript\r\n// packages/ember-data/lib/system/store.js\r\n\r\nadapterFor: function(type) {\r\n    type = this.modelFor(type);\r\n\r\n    var adapter = this.lookupAdapter(type.typeKey) || this.lookupAdapter('application');\r\n\r\n    return adapter || get(this, 'defaultAdapter');\r\n  },\r\n```\r\nto something like\r\n\r\n```javascript\r\n// packages/ember-data/lib/system/store.js\r\nfunction tailsOf (delimiter, string) { \r\n  return [] if Ember.isBlank(string)\r\n  return [string].concat(tailsOf(delimiter, string.split(delimiter).slice(1)))\r\n}\r\n\r\n... // other stuff\r\n\r\nadapterFor: function(type) {\r\n    type = this.modelFor(type);\r\n\r\n    var adapter = tailsOf(\"/\", type.typeKey).find(this.lookupAdapter.bind(this)) || this.lookupAdapter('application');\r\n\r\n    return adapter || get(this, 'defaultAdapter');\r\n  },\r\n```\r\n\r\nPlease let me know if this is something you guys will approve of, that way, I know if I should commit time into testing and pull-requesting."},"comment":{"url":"https://api.github.com/repos/emberjs/data/issues/comments/85183862","html_url":"https://github.com/emberjs/data/issues/2928#issuecomment-85183862","issue_url":"https://api.github.com/repos/emberjs/data/issues/2928","id":85183862,"user":{"login":"foxnewsnetwork","id":1010423,"avatar_url":"https://avatars.githubusercontent.com/u/1010423?v=3","gravatar_id":"","url":"https://api.github.com/users/foxnewsnetwork","html_url":"https://github.com/foxnewsnetwork","followers_url":"https://api.github.com/users/foxnewsnetwork/followers","following_url":"https://api.github.com/users/foxnewsnetwork/following{/other_user}","gists_url":"https://api.github.com/users/foxnewsnetwork/gists{/gist_id}","starred_url":"https://api.github.com/users/foxnewsnetwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foxnewsnetwork/subscriptions","organizations_url":"https://api.github.com/users/foxnewsnetwork/orgs","repos_url":"https://api.github.com/users/foxnewsnetwork/repos","events_url":"https://api.github.com/users/foxnewsnetwork/events{/privacy}","received_events_url":"https://api.github.com/users/foxnewsnetwork/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T20:36:00Z","updated_at":"2015-03-23T20:36:00Z","body":"In what way? I mean, it seems reasonably sane to me since Ember does something like this with its routes (and controllers); for example, if you have:\r\n\r\n```bash\r\napp\r\n  -- routes\r\n    -- kennels\r\n      -- dog\r\n        -- status.js\r\n      -- dog.js\r\n    -- application.js\r\n    -- kennels.js\r\n```\r\nAnd you go to '/kennels/dog/4/status', the Ember hamster runs through and patronizes all the routes you have declared in status.js, dog.js, and kennels.js before finally slinking away to the route declared in application.js. So why not also do it for models looking for adapters?"}}