I'm getting a return as array ( []
) from a scope with find_by
and I want the return to be empty ( null
).
Here are some snippets of the code:
class Dispute::Conference < ApplicationRecord
...
belongs_to :dispute, counter_cache: true
scope :scheduled, -> { find_by state: :scheduled }
...
end
It is a has_many
relationship, so it is normal to return an array if no result was found.
class Dispute < ApplicationRecord
...
has_many :conferences, dependent: :destroy
...
end
As I'm using a scope, and I expect only one result of the filter, I thought it would return null
if no result was found.
Is there any way to return null
, for this specific case?