I've user and address.
One user has one address. so I use applied following association.
class User < ApplicationRecord
has_one :address, dependent: :destroy
end
and in controller:
render json: User.find(1).as_json(include: :address)
The problem is:
it returns a JSON object like
{id: 1, name: "abc", address: {id: 1, user_id: 1}}
if I have an address for user id 1.
but I don't have an address of any user. it returns
{id: 1, name: "abc"}
but I want response like
{id: 1, name: "abc", address: {}}
if user don't have address.