On Friday, February 22, 2019 at 3:59:03 PM UTC-8, Barbara Carradini wrote:
>
> I'm attempting to upgrade from Ruby 2.3.8 to Ruby 2.5.4, but have 
> encountered and issue with the association_proxies plugin since upgrading:
>
> *Environment:*
>
> ruby 2.5.4
> sequel 5.4.0
> sequal_pg 1.11.0
>
> *Sequel Plugins:*
>
> Sequel::Model.plugin :timestamps
> Sequel::Model.plugin :association_proxies
> Sequel::Model.plugin :association_dependencies
> Sequel::Model.plugin :json_serializer
> Sequel::Model.plugin :defaults_setter
>
> *Model:*
>
> module DonorSee
>   class User < Sequel::Model
>   ...
>     one_to_many :gifts_given, class: 'DonorSee::Gift'
>   ...
>   end
> end
>
> *Error:*
>
> pry(main)> User.with_pk(98).gifts_given.sum(:amount_cents)
>
> NoMethodError: undefined method `+' for :amount_cents:Symbol
>
> The above used to work, thanks to the association_proxies plugin. Now it 
> doesn't and I'm not sure why.
>
> Alternatively, I can execute the sum() method on a filtered Gift dataset 
> like so:
>
> pry(main)> Gift.where(user_id: 98).sum(:amount_cents)
> => 57400
>
>
> I've tried looking in various release notes for an answer, but am stuck. 
> Thanks in advance!
>
>
This isn't a Sequel issue, it is a Ruby issue, which is why it is not in 
the release notes.  association_proxies by default will call methods on the 
array of associated objects (if an array responds to the method), and to 
the association dataset otherwise.  Array#sum was added in Ruby 2.4, hence 
the behavior change you are seeing.

You can pass a block to the association_proxies plugin for control over 
whether the methods sent to the proxy are forwarded to the array of 
associated objects (block returns false or nil) or the association dataset 
(otherwise).  See the association_proxies plugin documentation for details.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to