yosiat / panko_serializer

High Performance JSON Serialization for ActiveRecord & Ruby Objects
https://panko.dev
MIT License
592 stars 36 forks source link

Allow more flexibility in how serializers are resolved when strings are passed to the serializer option #119

Closed ryoung closed 2 years ago

ryoung commented 2 years ago

This PR allows has_one and has_many associations to use a different serializer than the association name, if a string is passed in for the serializer.

Using a real world example - If you have this defined: has_one :current_driver, serializer: "User" in a Vehicle, the serializer resolver will always look for CurrentDriverSerializer, which is not the correct serializer, because we wanted a UserSerializer.