# How to access a different model in a connector?

**URL:** <https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916>\
**Category:** Development\
**Created:** [August 2, 2021, 5:04pm UTC](https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916 "2021-08-02T17:04:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)\
**Post date:** [August 2, 2021, 5:04pm UTC](https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916/1 "2021-08-02T17:04:48Z")

</div>

I’m pretty close, but I can’t figure it out. I’ve created a connector here `connectors/revision-user-details-after`:

 ![CleanShot 2021-08-02 at 18.52.58@2x](https://global.discourse-cdn.com/meta/original/3X/b/3/b385b451d541900cbdf3e422ec0fda3864a694d0.png)

In my connector class, I can access `args` and `component` via the `shouldRender` method, which lets me access the current username and the post id:

```js
export default {
  shouldRender(args, component) {
    console.log('postAuthor', args.model.username)
    console.log('postId', args.model.id)
  }
};

```

I’d also like to get the username of the user who _edited_ the post (in this case, “nachocab”), but `args.model` is a Post, not a PostRevision.

This is what the history modal looks like:

[https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/templates/modal/history.hbs#L5](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/templates/modal/history.hbs#L5)

And the history controller:

[https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/controllers/history.js#L74](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/controllers/history.js#L74)

How can I access the revision in the connector?

---

<div class="post-metadata">

**Author:** ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)\
**Post date:** [August 3, 2021, 12:46pm UTC](https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916/2 "2021-08-03T12:46:48Z")

</div>

Ah, I just realized I can do this!

```js
import Post from "discourse/models/post";

Post.loadRevision(args.model.id, args.model.version).then((result) => {
  const editorUsername = result.username;
  doSomethingElse();
});

```

**UPDATE**  
@eviltrout I thought I had this figured out, but I just realized that since `Post.loadRevision` returns a Promise, I can’t put it inside `shouldRender()`:

```plaintext
import Post from 'discourse/models/post';

export default {
  shouldRender(args, component) {
    // returning a promise doesn't work
    return Post.loadRevision(args.model.id, args.model.version).then((revision) => {
      return args.model.username !== revision.username;
    });
  },
};

```

Is there another way of doing this?

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [August 5, 2021, 1:41pm UTC](https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916/3 "2021-08-05T13:41:21Z")

</div>

You could move it out of the connector into a new component you insert, and have it show a “Loading…” state until the promise is fulfilled, at which point you `set` the value and display it.

---

<div class="post-metadata">

**Author:** ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)\
**Post date:** [August 5, 2021, 5:22pm UTC](https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916/4 "2021-08-05T17:22:37Z")

</div>

Thanks, Robin. Your tip was just what I needed. 🎉

This works, but I wonder if the direct `ajax` call is needed (when I took the connector path, I had access to the Post but not the Revision; now that I took the component path, I have access to the Revision, but not the Post 🤔)

```handlebars
{{! templates/connectors/revision-user-details-after/reply-to-editor.hbs }}
{{reply-to-editor
  postId=model.post_id
  postVersion=model.current_version
  revisionAuthor=model.username
}}

```

```handlebars
{{! templates/components/reply-to-editor.hbs }}
{{#if isVisible}}
  {{d-button
    action=(action 'replyToEditor')
    label='test'
  }}
{{/if}}

```

```js
{{! javascripts/discourse/components/reply-to-editor.js.es6 }}
import { ajax } from 'discourse/lib/ajax';

export default Ember.Component.extend({
  isVisible: true,

  didRender() {
    if (!this.get('postId')) return;

    ajax(`/posts/${this.get('postId')}`).then((post) => {
      // only show the button if the revision author is not the post author
      this.set('isVisible', this.get('revisionAuthor') !== post.username);
    });
  }
});

```

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [August 5, 2021, 5:56pm UTC](https://meta.discourse.org/t/how-to-access-a-different-model-in-a-connector/198916/5 "2021-08-05T17:56:55Z")

</div>

I’m not sure why you don’t have access to the same variables in the template as the connector. It should be identical!
