candy icon indicating copy to clipboard operation
candy copied to clipboard

Items returned by Candy::Collection shouldn't cache all values as nil

Open dominikh opened this issue 15 years ago • 4 comments
trafficstars

class Email
  include Candy::Piece
end

class Emails
  include Candy::Collection
  collects Email
end

Emails.each do |email|
  email.provider # => nil
  email.refresh
  email.provider # => "some value" 
end

Imho, it shouldn't be required to manually call email.refresh

dominikh avatar Jun 17 '10 15:06 dominikh

Good catch. I'll investigate what's going on there, thanks.

SFEley avatar Jun 17 '10 15:06 SFEley

Same here. I'm using MongoDB 1.4.4 on Ubuntu 10.04, with Candy 0.2.10.

unindented avatar Jul 20 '10 18:07 unindented

I found the issue here. Its in the initializer for the Collection::ClassMethods

Line 62 of collection.rb

if conditions.is_a?(Hash)
    @_candy_options = {:fields => '_id'}.merge(extract_options(conditions))
    @_candy_query.merge!(conditions)
  else
    @_candy_options = {:fields => '_id'}
  end

The problem is that by default conditions is set to {} so Candy always pulls just the _id field, hence all other attributes are nil.

I'm not really sure how to fix it without brute forcing @_candy_options back to {}.

remkade avatar Nov 10 '11 22:11 remkade

I forked Ben Hosking's updated repo and made a fix that corrects this issue.

remkade avatar Nov 10 '11 23:11 remkade