datamapper / dm-aggregates

DataMapper plugin providing support for aggregates on collections
http://datamapper.org/
MIT License
16 stars 15 forks source link

Aggregate does not accept properties on relationships in :fields #13

Open tpitale opened 13 years ago

tpitale commented 13 years ago

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:inmap!' 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):2 from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/railties-3.0.8/lib/rails/commands/console.rb:44:instart' 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

'

jpr5 commented 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, ...)
tpitale commented 13 years ago

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:ineach' 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:inassert_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:ineach' 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:inupdate' 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:inscoped_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:instart' 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:ineach' 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:inassert_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:ineach' 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:inupdate' 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:inscoped_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:instart' 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:inmap!' 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:instart' 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

'