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

- old
+ new

@@ -185,14 +185,14 @@ # # @return [Model|nil] def first(*args) n = args.first || 1 - return scan_limit(n).to_a.first(*args) if @query.blank? + return self.dup.scan_limit(n).to_a.first(*args) if @query.blank? return super if @key_fields_detector.non_key_present? - record_limit(n).to_a.first(*args) + self.dup.record_limit(n).to_a.first(*args) end # Returns the last item matching the criteria. # # Post.where(links_count: 2).last @@ -484,19 +484,21 @@ # memory footprint. # # @return [Array] def pluck(*args) fields = args.map(&:to_sym) - @project = fields + scope = self.dup + scope.project(*fields) + if fields.many? - items.map do |item| + scope.items.map do |item| fields.map { |key| Undumping.undump_field(item[key], source.attributes[key]) } end.to_a else key = fields.first - items.map { |item| Undumping.undump_field(item[key], source.attributes[key]) }.to_a + scope.items.map { |item| Undumping.undump_field(item[key], source.attributes[key]) }.to_a end end private @@ -511,10 +513,11 @@ # Raw items like they are stored before type casting def items raw_pages.lazy.flat_map { |items, _| items } end + protected :items # Arrays of records, sized based on the actual pages produced by DynamoDB # # @return [Enumerator] an iterator of the found records. # @@ -566,10 +569,10 @@ end end def issue_scan_warning Dynamoid.logger.warn 'Queries without an index are forced to use scan and are generally much slower than indexed queries!' - Dynamoid.logger.warn "You can index this query by adding index declaration to #{source.to_s.downcase}.rb:" + Dynamoid.logger.warn "You can index this query by adding index declaration to #{source.to_s.underscore}.rb:" Dynamoid.logger.warn "* global_secondary_index hash_key: 'some-name', range_key: 'some-another-name'" Dynamoid.logger.warn "* local_secondary_index range_key: 'some-name'" Dynamoid.logger.warn "Not indexed attributes: #{query.keys.sort.collect { |name| ":#{name}" }.join(', ')}" end