# Adapter updates in beta-16.1?

**URL:** <https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694>\
**Category:** Ember Data\
**Created:** [April 1, 2015, 5:22pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694 "2015-04-01T17:22:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToddSmithSalter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toddsmithsalter/32/12772_2.png) [@ToddSmithSalter](https://discuss.emberjs.com/u/ToddSmithSalter)\
**Post date:** [April 1, 2015, 5:22pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/1 "2015-04-01T17:22:56Z")

</div>

Hey friends,

Hoping someone can help spot the issue I’m having or maybe point me in the right direction. In my app, we use a repository pattern to alter the namespace for certain requests. An example would be when we want to make a request to `https://apiserver.com/v1/users/:id/workspaces`. By default my adapter namespace is set to `v1`. Prior to sending the request with ember-data, I append `users/:id` to the namespace of the adapter, then send the request with `store.find('workspace')`. Up until ember-data 1.0.0-beta.15, this approach has worked swimmingly. I find that after upgrading to `beta-16.1` that the namespace alteration isn’t picked up by the buildURL method, or I suppose it occurs after buildURL is run.

- Is it possible that this has anything to do with the Snapshot API?
- With the [new injection method in initializers](http://emberjs.com/deprecations/v1.x/#toc_access-to-instances-in-initializers), could that have anything to do with it? I’m not doing any `container.lookup` in the initializer, so this may be a non-issue.

```auto
// repositories/workspace.js
  appendResources: function () {
    this.clearAppendedResources();

    var adapterNamespace = this.get('adapter.namespace'), // We're injecting the adapter into repositories
        prefix = [adapterNamespace];

    if (arguments.length) {
      // For each argument, lookup the related id. Push both to the namespace
      for (var i=0; i < arguments.length; i++) {
        prefix.push(arguments[i]);
      }
      this.set('adapter.namespace', prefix.join('/'));
    }
  },

  // The method that ties it all together
  getWorkspacesByUser: function (user_id, params) {
    var self = this;

    if (params === undefined) {
      params = {};
    }

    this.appendResources('users', user_id); // We alter the namespace here
    this.setupIncludes(); // We append some ?include=yadayada params here

    // Make the request! Should be to /v1/users/:id/workspaces
    return this.store.find('workspace', params).finally(function () {
      // Clean up all the things
      self.clearIncludes();
      self.clearAppendedResources();
    });
  }

```

Here’s how we’re building the URL in the adapter for reference:

```auto
  // adapters/workspace.js
  buildURL: function(type, id, snapshot) {
    var url = this._super(type, id, snapshot);
    return this.buildIncludeURL(url);
  },

  buildIncludeURL: function (url) {
    if (this.includes.length) {
      url += '?include=' + this.includes.join(',');
    }
    return url;
  }

```

---

<div class="post-metadata">

**Author:** ![jmurphyau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jmurphyau/32/16684_2.png) [@jmurphyau](https://discuss.emberjs.com/u/jmurphyau)\
**Post date:** [April 1, 2015, 8:36pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/2 "2015-04-01T20:36:51Z")

</div>

> [@ToddSmithSalter](#):
>
> // We’re injecting the adapter into repositories

Yu say you’re injecting the adapter into repositories?

The adapters and serialisers have changed in that they are no longer singleton. Each instance of a store maintains its own serialiser and adapter instances… This might be part of your problem - your altering an injected adapter while requests are using a different adapter (one your store has created)

---

<div class="post-metadata">

**Author:** ![ToddSmithSalter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toddsmithsalter/32/12772_2.png) [@ToddSmithSalter](https://discuss.emberjs.com/u/ToddSmithSalter)\
**Post date:** [April 1, 2015, 8:42pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/3 "2015-04-01T20:42:01Z")

</div>

That’s interesting and the most logical conclusion. So when requests are made the store, a new instance of an adapter and serializer is instantiated for each request?

---

<div class="post-metadata">

**Author:** ![jmurphyau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jmurphyau/32/16684_2.png) [@jmurphyau](https://discuss.emberjs.com/u/jmurphyau)\
**Post date:** [April 1, 2015, 8:55pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/4 "2015-04-01T20:55:59Z")

</div>

Nope - the store maintains a single instance. It uses that one instance for each request.

When calling `store.adapterFor('workspace')` you will always get back the same instance.

---

<div class="post-metadata">

**Author:** ![ToddSmithSalter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toddsmithsalter/32/12772_2.png) [@ToddSmithSalter](https://discuss.emberjs.com/u/ToddSmithSalter)\
**Post date:** [April 9, 2015, 4:30pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/5 "2015-04-09T16:30:10Z")

</div>

Ah. Sorry for my lack of knowledge about ED core. I’m assuming this means adapters are no longer registered with the container and bound directly to the model instance?

Is there a specific place/source file I should look at so I can grok this without asking you a bo-jillion questions?

---

<div class="post-metadata">

**Author:** ![jmurphyau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jmurphyau/32/16684_2.png) [@jmurphyau](https://discuss.emberjs.com/u/jmurphyau)\
**Post date:** [April 9, 2015, 9:33pm UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/6 "2015-04-09T21:33:48Z")

</div>

Adapters are still registered against the container - they initially come from the container - when the store first creates them…

You could look at [this pull request](https://github.com/emberjs/data/pull/2617) which is the one that implemented this particular change - but don’t mind me - if you have any more questions (and I’m capable of answering) I’m happy to help (:

---

<div class="post-metadata">

**Author:** ![ToddSmithSalter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toddsmithsalter/32/12772_2.png) [@ToddSmithSalter](https://discuss.emberjs.com/u/ToddSmithSalter)\
**Post date:** [April 10, 2015, 1:31am UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/7 "2015-04-10T01:31:43Z")

</div>

So the benefit of having adapters and serializers not registered as singletons is to prevent collisions between apps using multiple stores or stores registered other than store:main? Neat. So another question…if I want to affect some properties on the adapter or serializer prior to making a request, would it be best to lookup the specific adapter instance with store.adapterFor(‘type’)?

p.s. Great work on that PR. You da man.

---

<div class="post-metadata">

**Author:** ![jmurphyau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jmurphyau/32/16684_2.png) [@jmurphyau](https://discuss.emberjs.com/u/jmurphyau)\
**Post date:** [April 10, 2015, 1:53am UTC](https://discuss.emberjs.com/t/adapter-updates-in-beta-16-1/7694/8 "2015-04-10T01:53:14Z")

</div>

The whole thing started because the EmbeddedRecordMixin used the `store` property which was always the `store:main` - so there was no way to get embedded records in a store other than `store:main`.

`store.adapterFor('type')` is the way to go - yep.
