A proxy for the association. Calling an array method will load the associated objects and call the method on the associated object array. Calling any other method will call that method on the association’s dataset.
Constants
DEFAULT_PROXY_TO_DATASET | = | proc do |opts| array_method = array.respond_to?(opts[:method]) if !array_method && opts[:method] == :filter Sequel::Deprecation.deprecate "The behavior of the #filter method for association proxies will change in Ruby 2.6. Switch from using #filter to using #where to conserve current behavior." end !array_method end |
Default proc used to determine whether to send the method to the dataset. If the array would respond to it, sends it to the array instead of the dataset. |
Public Class methods
new(instance, reflection, proxy_argument, &proxy_block)
Set the association reflection to use, and whether the association should be reloaded if an array method is called.
[show source]
# File lib/sequel/plugins/association_proxies.rb 85 def initialize(instance, reflection, proxy_argument, &proxy_block) 86 @instance = instance 87 @reflection = reflection 88 @proxy_argument = proxy_argument 89 @proxy_block = proxy_block 90 end
Public Instance methods
method_missing(meth, *args, &block)
Call the method given on the array of associated objects if the method is an array method, otherwise call the method on the association’s dataset.
[show source]
# File lib/sequel/plugins/association_proxies.rb 94 def method_missing(meth, *args, &block) 95 v = if @instance.model.association_proxy_to_dataset.call(:method=>meth, :arguments=>args, :block=>block, :instance=>@instance, :reflection=>@reflection, :proxy_argument=>@proxy_argument, :proxy_block=>@proxy_block) 96 @instance.public_send(@reflection[:dataset_method]) 97 else 98 @instance.send(:load_associated_objects, @reflection, @proxy_argument, &@proxy_block) 99 end 100 v.public_send(meth, *args, &block) 101 end