Hi there,

What about allowing to pass a proc to belongs_to's optional flag?

So instead of the following:

class Transaction < ApplicationRecord
  belongs_to :category, optional: true
  validates :category, presence: { message: :required }, if: :auto_created?
end

We could write:

class Transaction < ApplicationRecord
  belongs_to :category, optional: ->(record) { record.auto_created? }
end


I'm happy to submit a PR if you agree with the suggestion.

Cheers,
Lucas.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to