# No context when registering transforms

**URL:** <https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815>\
**Category:** Ember Data\
**Created:** [July 15, 2013, 9:43pm UTC](https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815 "2013-07-15T21:43:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![knownasilya](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/knownasilya/32/12912_2.png) [@knownasilya](https://discuss.emberjs.com/u/knownasilya)\
**Post date:** [July 15, 2013, 9:43pm UTC](https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815/1 "2013-07-15T21:43:22Z")

</div>

In trying to get information about the attribute that’s being transformed in my `registerTransform` function. Mainly I need the name of the attribute.

My use case is for creating a `metaObject` which would have a value and meta property. The value would be the unchanged value, and the meta will be populated from a key/value hash based on the attribute. The objects `toString` would return the value.

It would be used like this:

```nohighlight
    {{username}} {{! "Bob"}}
    {{username.meta}} {{! "User Name"}}

```

Another use case could be for transforming keys to values, so if the data you get from the server are keys/ids that have a corresponding value, it would be necessary to know the attribute type, since keys could overlap across different attributes.

```javascript
    DS.RESTAdapter.registerTransform("keyValueObject", { 
      serialize: function (value) {
        return value.get("key");
      },
      deserialize: function (key) {
        var keyValues = {
          3: "768 kbps - 1.5 mbps",
          4: "1.5 - 3 mbps",
          5: "3 - 6 mbps",
          default: "Not Specified"
        };

        // Missing a way to know what type of attribute this is..
        // would have an object: attributeMap = { attributeType: {...}, ... };

        return Ember.Object.create({
          value: keyValues[key] || keyValues.default,
          key: key,
          toString: function () {
            return this.value;
          }
        });
      }
    });

```

The problem is that there is no such parameter, nor does `this` hold any context.

The work around, would be to create a separate transform for each attribute, with it’s own key/value pairs.

---

<div class="post-metadata">

**Author:** ![pzuraq](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/pzuraq/32/13754_2.png) [@pzuraq](https://discuss.emberjs.com/u/pzuraq)\
**Post date:** [August 3, 2013, 1:55am UTC](https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815/2 "2013-08-03T01:55:37Z")

</div>

I’m having exactly this problem and it would be very useful to be able to get the attribute name when registering transforms. Is there anything new about this?

---

<div class="post-metadata">

**Author:** ![knownasilya](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/knownasilya/32/12912_2.png) [@knownasilya](https://discuss.emberjs.com/u/knownasilya)\
**Post date:** [August 3, 2013, 12:58pm UTC](https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815/3 "2013-08-03T12:58:57Z")

</div>

Nothing that I know of, yet. I created an [issue](https://github.com/emberjs/data/issues/1107), maybe it’ll get some attention.

---

<div class="post-metadata">

**Author:** ![stefan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/stefan/32/14174_2.png) [@stefan](https://discuss.emberjs.com/u/stefan)\
**Post date:** [August 3, 2013, 2:42pm UTC](https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815/4 "2013-08-03T14:42:23Z")

</div>

oops… accidentally hit delete.

Although more context for the transforms isn’t a bad idea. Typically for these sorts of “humanized” transforms I use either a handlebars helper or computed property to decorate for human consumption. Leaving the adapter level transforms strictly for data transport.

---

<div class="post-metadata">

**Author:** ![knownasilya](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/knownasilya/32/12912_2.png) [@knownasilya](https://discuss.emberjs.com/u/knownasilya)\
**Post date:** [August 5, 2013, 12:49pm UTC](https://discuss.emberjs.com/t/no-context-when-registering-transforms/1815/5 "2013-08-05T12:49:19Z")

</div>

That is a good point, thanks for sharing your view @stefan. I’ll close the issue.
