diff --git a/lib/active_fedora/querying.rb b/lib/active_fedora/querying.rb index 66065a579..9b11da005 100644 --- a/lib/active_fedora/querying.rb +++ b/lib/active_fedora/querying.rb @@ -60,9 +60,10 @@ def default_sort_params # @param [Hash] opts # @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel def find_each( conditions={}, opts={}) + cast = opts.delete(:cast) find_in_batches(conditions, opts.merge({:fl=>SOLR_DOCUMENT_ID})) do |group| group.each do |hit| - yield(find_one(hit[SOLR_DOCUMENT_ID], opts[:cast])) + yield(find_one(hit[SOLR_DOCUMENT_ID], cast)) end end end diff --git a/lib/active_fedora/relation.rb b/lib/active_fedora/relation.rb index 8e8a6e14c..3ee683a18 100644 --- a/lib/active_fedora/relation.rb +++ b/lib/active_fedora/relation.rb @@ -162,7 +162,7 @@ def all(*args) def to_a return @records if loaded? - args = {} #:cast=>true} + args = @klass == ActiveFedora::Base ? {:cast=>true} : {} args[:rows] = @limit_value if @limit_value args[:sort] = @order_values if @order_values diff --git a/spec/unit/query_spec.rb b/spec/unit/query_spec.rb index b1e273113..373cb03ce 100644 --- a/spec/unit/query_spec.rb +++ b/spec/unit/query_spec.rb @@ -49,8 +49,8 @@ class Basic < ActiveFedora::Base end describe "called without a specific class" do it "should specify a q parameter" do - ActiveFedora::Base.should_receive(:find_one).with("changeme:30", nil).and_return("Fake Object1") - ActiveFedora::Base.should_receive(:find_one).with("changeme:22", nil).and_return("Fake Object2") + ActiveFedora::Base.should_receive(:find_one).with("changeme:30", true).and_return("Fake Object1") + ActiveFedora::Base.should_receive(:find_one).with("changeme:22", true).and_return("Fake Object2") mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}] mock_docs.should_receive(:has_next?).and_return(false) ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>'*:*', :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})