# What is this code add\_to\_serializer in all these plugins

**URL:** https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913
**Category:** Development
**Created:** [March 12, 2017, 5:07am UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913 "2017-03-12T05:07:15Z")
**Posts on this page:** 7
**Page:** 2

<div class="post-metadata">

### Author: ![Cyrine](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@Cyrine](https://meta.discourse.org/u/Cyrine)
#### Post date: [August 22, 2020, 3:01pm UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/23 "2020-08-22T15:01:36Z")

</div>

If possible, can you please share the link of the plugin that you were working on at that time?

---

<div class="post-metadata">

### Author: ![Mgcs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mgcs/32/202507_2.png) [@Mgcs](https://meta.discourse.org/u/Mgcs)
#### Post date: [January 12, 2021, 4:05am UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/24 "2021-01-12T04:05:33Z")

</div>

Thanks for the great explanations. Am I right to assume that it would be possible to use add\_to\_serializer, something like op\_likes? I’m not sure why this happens, but I can only have access to the op\_likes\_count when I order by it (as in order=op\_likes), but I wanted to have such numbers without having to order by it.

---

<div class="post-metadata">

### Author: ![Stanzilla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stanzilla/32/166422_2.png) [@Stanzilla](https://meta.discourse.org/u/Stanzilla)
#### Post date: [January 21, 2021, 9:45pm UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/25 "2021-01-21T21:45:08Z")

</div>

Is there also a way to use it from JavaScript? I’m currently looking at [`showOpLikes` doesn't work right away, but after clicking back and forth - #6 by pfaffman](https://meta.discourse.org/t/showoplikes-doesnt-work-right-away-but-after-clicking-back-and-forth/143546/6) which was closed.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [January 21, 2021, 9:49pm UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/26 "2021-01-21T21:49:45Z")

</div>

> [@Stanzilla](#):
>
> Is there also a way to use it from JavaScript?

No, you can’t change an API from a client 🙂

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [January 21, 2021, 9:58pm UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/27 "2021-01-21T21:58:11Z")

</div>

> [@net\_deamon](#):
>
> ```plaintext
> # I guess this should be the default @ discourse. PR maybe?
> add_to_serializer(:user, :custom_fields, false) {
> 
> ```

This should absolutely not be the default. Not all user custom fields should be displayed to the user (e.g. see Staff Notes).

---

<div class="post-metadata">

### Author: ![jimkleiber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimkleiber/32/121814_2.png) [@jimkleiber](https://meta.discourse.org/u/jimkleiber)
#### Post date: [April 3, 2023, 5:15pm UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/28 "2023-04-03T17:15:11Z")

</div>

I wonder if “add to serializer” could be a checkbox when creating a custom user field in the UI. And then the PR could be to check if the custom user field has add to serializer and then if so, add it.

---

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [August 2, 2024, 11:07am UTC](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913/29 "2024-08-02T11:07:44Z")

</div>

5 posts were split to a new topic: [Adding to user serializer does not work for the current user object](https://meta.discourse.org/t/adding-to-user-serializer-does-not-work-for-the-current-user-object/319809)

[Previous page](https://meta.discourse.org/t/what-is-this-code-add-to-serializer-in-all-these-plugins/58913.md?page=1)
