Thanks Rafael, good point.

However, the problem by using the code I sent is the inconsistency:
in the first line it contains optional while the second contains a presence
validation.

Cheers,


On Tue, 7 Feb 2017 at 23:41 Rafael Mendonça França <[email protected]>
wrote:

> I believe this make `belongs_to` too complex and open a precedent to
> people want to customize the validation in other ways using the
> `belongs_to` syntax. The required validation is just a convenience. It is a
> good default but sometimes people want more than the default. In those
> cases they should be explicitly defining their own validation as your
> example.
>
> On Mon, Feb 6, 2017 at 9:51 PM Lucas Caton <[email protected]> wrote:
>
> Hi all,
>
> Any thoughts on this?
>
> *Lucas Caton*
> @lucascaton <https://twitter.com/lucascaton> | lucascaton.com.br
>
>
>
> On Wed, 1 Feb 2017 at 18:40 Lucas Caton <[email protected]> wrote:
>
> 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 a topic in the
> Google Groups "Ruby on Rails: Core" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/rubyonrails-core/V-padeQT7SQ/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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.
>
> --
>
> 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.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ruby on Rails: Core" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/rubyonrails-core/V-padeQT7SQ/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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.
>
-- 
*Lucas Caton*
@lucascaton <https://twitter.com/lucascaton> | lucascaton.com.br

-- 
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