4
I’m getting a return as an array ([]) of a scope with find_by and I wish the return to be empty (null).
See below some snippets of the code:
class Dispute::Conference < ApplicationRecord
...
belongs_to :dispute, counter_cache: true
scope :scheduled, -> { find_by state: :scheduled }
...
end
It’s a relationship has_many, then it is normal to return an array if no result is found.
class Dispute < ApplicationRecord
...
has_many :conferences, dependent: :destroy
...
end
Since I’m using a scope, and I expect only one filter result, I thought it would return null if no results were found.
Is there any way to return null, for this specific case?
An important detail, I switched
find_byforwhere, for some reason that I can not explain in some cases the return generates problems with theActiveModel::Serializer.– Bruno Wego