I'm struggling to see how to translate my example into this style.

This is the best I can come up with (and looks horribley messy):

client.attributes = params[:client]

if client.name_changed?
  client.save # triggers touch on the associated project
else
  ActiveRecord::Base.no_touching do
    client.save # no touch triggered
  end
end


On Tue, Nov 5, 2013 at 10:44 AM, Rafael Mendonça França <
[email protected]> wrote:

> This is related to this:
>
> https://github.com/rails/rails/pull/12772
>
> In my opinion I prefer to have that kind of explicit feature disable
> instead some magic lambda condition.
>
> Rafael Mendonça França
> http://twitter.com/rafaelfranca
> https://github.com/rafaelfranca
>
>
> On Tue, Nov 5, 2013 at 1:13 PM, Andrew Kaspick <[email protected]> wrote:
>
>> Something that I believe would be useful to prevent overzealous "updates"
>> via touch would be to allow a lambda to be specified to determine if the
>> touch should occur or not.
>>
>> class Client
>>   belongs_to :project, touch: -> {|rec| rec.name_changed?}
>> end
>>
>> In this case, the project association is only "touched" if only the
>> client name changes.  This way if there's a lot of client data that has no
>> value to the project object and the project is only concerned with a change
>> to just one client attribute (for example) this would only trigger the
>> touch in that case.
>>
>> Since an attribute can be specified for touch, then perhaps the option
>> should be called touch_if and the touch is always performed when the main
>> object is destroyed.
>>
>> class Client
>>   belongs_to :project, touch: true, touch_if: -> {|rec|
>> rec.name_changed?}
>> end
>>
>> Thoughts?
>>
>>  --
>> 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 http://groups.google.com/group/rubyonrails-core.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> 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 http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to