Open tpitale opened 13 years ago
I've never tried it before, so YMMV, but if :fields => []
can have DM::Property's in it, then try it?
Problem.aggregate(:id.count, :fields => [User.id, User.email], :unique => true, ...)
Thanks for the suggestion. I tried it a few different ways, all with differing errors.
Problem.aggregate(:id.count, :fields => [:user_id, User.email], :unique => true)
ArgumentError: +options[:field]+ entry :email does not map to a property in Problem
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:805:in block in assert_valid_fields' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:796:in
each'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:796:in assert_valid_fields' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/query.rb:23:in
assert_valid_fields_with_operator'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:768:in block in assert_valid_options' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:766:in
each'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:766:in assert_valid_options' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:363:in
update'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:386:in merge' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/model.rb:753:in
scoped_query'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:180:in aggregate' from (irb):7 from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in
start'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:8:in start' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands.rb:23:in
<top (required)>'
from script/rails:6:in require' from script/rails:6:in
Problem.aggregate(:id.count, :fields => [:user_id, Problem.user.email], :unique => true)
ArgumentError: +options[:fields]+ entry nil of an unsupported object NilClass
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:809:in block in assert_valid_fields' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:796:in
each'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:796:in assert_valid_fields' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/query.rb:23:in
assert_valid_fields_with_operator'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:768:in block in assert_valid_options' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:766:in
each'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:766:in assert_valid_options' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:363:in
update'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/query.rb:386:in merge' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-core-1.1.0/lib/dm-core/model.rb:753:in
scoped_query'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:180:in aggregate' from (irb):9 from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in
start'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:8:in start' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands.rb:23:in
<top (required)>'
from script/rails:6:in require' from script/rails:6:in
Problem.aggregate(:id.count, :fields => [:user_id, Problem.user], :unique => true)
ArgumentError: +field+ should be DataMapper::Query::Operator or Symbol or DataMapper::Property, but was DataMapper::Query::Path
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:158:in block in aggregate' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:158:in
map!'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:158:in aggregate' from (irb):14 from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in
start'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:8:in start' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands.rb:23:in
<top (required)>'
from script/rails:6:in require' from script/rails:6:in
Problem.aggregate(:id.count, :fields => [:user_id, "users.email"], :unique => true, :links => [:user])
ArgumentError: +field+ should be DataMapper::Query::Operator or Symbol or DataMapper::Property, but was String from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:158:in'
block in aggregate' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:158:in
map!' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:158:inaggregate' from (irb):2 from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in
start' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:8:instart' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands.rb:23:in
<top (required)>' from script/rails:6:inrequire' from script/rails:6:in