I am building a Rest API using rails-api and active-model-serializer to easily filter the required fields in the JSON. I am also using the has_one
association in these serializers. All I wanted to know is how do I specify a different key name for the has_one
attribute.
That is, I have two models say: Employee
and Address
, and there is a has_one :address
in say EmployeeSerializer
. The response that I get is:
{
id: 1,
address: {
street: "some_street",
city: "some_city"
}
}
But I would like to get the following response:
{
id: 1,
stays: {
street: "some_street",
city: "some_city"
}
}
I tried using has_one :address, :key => :stays
, but that doesn't seem to work.