active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Embedded association not using serializer #2247

Open jcpny1 opened this issue 6 years ago • 10 comments

Issue #2247 was closed, but I'm having trouble figuring out what the resolution was.

jcpny1 avatar Dec 17 '19 21:12 jcpny1

@jcpny1 I closed it because it was attracting off-topic conversation and was stale.

The resolution IMHO is as follows

  1. Realize that the problem is really wanting to serialize a model-association as a resource-attribute
  2. Define the problem as 'how do I serialize a model using AMS'
  3. Look up how to serialize a model using AMS and stick that in our attribute definition
  4. profit

bf4 avatar Dec 17 '19 22:12 bf4

I have the exact same issue as the linked issue.

So I should do this?

attributes :child

def child
  ChildSerializer.new(object.child)
end

instead of this?

has_one :child # (also tried adding the :serializer option, didn't work)

If that's the case I'd say that defies the developer's expectation communicated by the feature

Update changing to the manual example above did work for me, but that really doesn't feel right. Not sure why I would or should use the association methods that I have serializers for. I always want the serializers used. I upgraded from 0.8 so it seems this worked as expected in 0.8?

joemsak avatar Dec 09 '20 00:12 joemsak

@joemsak unless you need to upgrade your version for some feature in 0.10 I recommend you stay on it at this point

bf4 avatar Dec 09 '20 01:12 bf4

I understand your point, and I think it still would be nice to know what to expect from this feature in the latest version, or to have this issue explained/clarified better.

joemsak avatar Dec 09 '20 15:12 joemsak

@joemsak I apologize but I'm not entirely sure what you're asking. I believe your issue is the same as the one I addressed in 2019, that you want to serialize a model relation as if it were an attribute. That being the case, the resolution is the same. In addition, if 0.8 is working for you you really should not try to update to 0.10. There's no benefit. I know you'd think there would be, but there isn't.

bf4 avatar Dec 09 '20 15:12 bf4

I know it is the same issue and I read the whole thing. I dont see any resolution just telling the OP how to “think” of the issue (model-relation vs resource-attribute). That’s not the same as what I and OP are asking for.

My issue is why doesn't “has_one” or the others use a serializer? Why shouldn't the developer expect this? It used to work that way in 0.8 apparently. What should the developer do if they want their associations to use their serializers?

Why provide instructions and guides on upgrading if you don’t think people should?

This is the only outstanding issue I am having since upgrading.

joemsak avatar Dec 09 '20 16:12 joemsak

I'm sorry to have to say it directly but your responses in this and the closed thread aren't helpful, and in fact are a bit rude and dismissive. We want to know why the association methods don't use the serializers and how to make them do that. I asked if your first comment meant I am expected to do it the way I showed and you still won't answer me. And if that is the answer, then I'd like the association methods to be clarified because if they don't use serializers (even when passing the :serializer option) then they don't make sense to me. I'm more than happy to hear the explanation, and I'm sure I could be convinced to the reasoning if it was just clarified.

joemsak avatar Dec 09 '20 16:12 joemsak

Also FYI, you did understand the issue https://github.com/rails-api/active_model_serializers/issues/2247#issuecomment-566263433 (your comment is absolutely correct here)

joemsak avatar Dec 09 '20 16:12 joemsak

Hi @joemsak To understand my perspective, I'm trying to do the bare minimum to be responsive while also not actually working on the gem anymore. 0.8->0.9 was a rewrite with new maintainers. 0.9->0.10 was a rewrite with new maintainers. I came only into the 0.10 rewrite and it just wasn't done right and we started considering another rewrite. There are quite a few gems born out of the learnings from this gem. It's unfortunate that AMS is basically dead at this point, but that's what has happened. I'm burnt out on it but don't want to abandon it.

I don't know why a has_one :association wouldn't use a serializer. it should. Maybe it can't find one? Maybe it's the adapter you're using? I'm not sure, but 0.8 was pretty good and if your app works on that, it probably performs better than on 0.10 too. That's why the main page is no longer 0.10.

I know you're putting in time and I appreciate it. Too many people don't do that, so I want to let you know I really appreciate your engagement. I'm sorry that I'm more limited right now and not meeting your needs.

bf4 avatar Dec 09 '20 18:12 bf4

@bf4 Thank you for your answer. Now it makes more sense to me. I get where you're coming from. We would love to migrate to a modern gem of course but the migration on a large legacy project will probably be hell.

joemsak avatar Dec 09 '20 18:12 joemsak