Re: [Rails-core] [Suggestion] Allow proc in belongs_to's optional flag

2017-02-07 Thread Lucas Caton
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 
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  wrote:
>
> Hi all,
>
> Any thoughts on this?
>
> *Lucas Caton*
> @lucascaton  | lucascaton.com.br
>
>
>
> On Wed, 1 Feb 2017 at 18:40 Lucas Caton  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
> rubyonrails-core+unsubscr...@googlegroups.com.
>
>
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> 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 rubyonrails-core+unsubscr...@googlegroups.com.
>
>
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> 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
> rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
*Lucas Caton*
@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 rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] [Suggestion] Allow proc in belongs_to's optional flag

2017-02-07 Thread Rafael Mendonça França
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  wrote:

> Hi all,
>
> Any thoughts on this?
>
> *Lucas Caton*
> @lucascaton  | lucascaton.com.br
>
>
>
> On Wed, 1 Feb 2017 at 18:40 Lucas Caton  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
> rubyonrails-core+unsubscr...@googlegroups.com.
>
>
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> 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 rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> 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 rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] [Suggestion] Allow proc in belongs_to's optional flag

2017-02-06 Thread Lucas Caton
Hi all,

Any thoughts on this?

*Lucas Caton*
@lucascaton  | lucascaton.com.br



On Wed, 1 Feb 2017 at 18:40 Lucas Caton  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
rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
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 rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


[Rails-core] [Suggestion] Allow proc in belongs_to's optional flag

2017-02-01 Thread Lucas Caton
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 rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.