lib/dynamoid/criteria/chain.rb in dynamoid-3.8.0 vs lib/dynamoid/criteria/chain.rb in dynamoid-3.9.0

- old
+ new

@@ -185,14 +185,14 @@ # # @return [Model|nil] def first(*args) n = args.first || 1 - return self.dup.scan_limit(n).to_a.first(*args) if @query.blank? + return dup.scan_limit(n).to_a.first(*args) if @query.blank? return super if @key_fields_detector.non_key_present? - self.dup.record_limit(n).to_a.first(*args) + dup.record_limit(n).to_a.first(*args) end # Returns the last item matching the criteria. # # Post.where(links_count: 2).last @@ -485,11 +485,11 @@ # # @return [Array] def pluck(*args) fields = args.map(&:to_sym) - scope = self.dup + scope = dup scope.project(*fields) if fields.many? scope.items.map do |item| fields.map { |key| Undumping.undump_field(item[key], source.attributes[key]) } @@ -523,10 +523,11 @@ # # @since 3.1.0 def pages raw_pages.lazy.map do |items, options| models = items.map { |i| source.from_database(i) } + models.each { |m| m.run_callbacks :find } [models, options] end.each end # Pages of items before type casting @@ -785,12 +786,12 @@ def sti_condition condition = {} type = @source.inheritance_field - if @source.attributes.key?(type) - class_names = @source.deep_subclasses.map(&:name) << @source.name - condition[:"#{type}.in"] = class_names + if @source.attributes.key?(type) && !@source.abstract_class? + sti_names = @source.deep_subclasses.map(&:sti_name) << @source.sti_name + condition[:"#{type}.in"] = sti_names end condition end end