Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Aggregate breaks when using :links => [] #12

Open
tpitale opened this issue Jun 27, 2011 · 2 comments
Open

Aggregate breaks when using :links => [] #12

tpitale opened this issue Jun 27, 2011 · 2 comments
Milestone

Comments

@tpitale
Copy link
Member

tpitale commented Jun 27, 2011

Problem.aggregate(:id.count, :fields => [:user_id], :unique => true, :links => [:user])

Will break like so:

DataObjects::SyntaxError: ERROR: missing FROM-clause entry for table "users"
LINE 1: ... "problems" INNER JOIN "problems" "problems_1" ON "users"."i...
^
(code: 16908420, sql state: 42P01, query: SELECT "problems"."user_id", COUNT("problems"."id") FROM "problems" INNER JOIN "problems" "problems_1" ON "users"."id" = "problems_1"."user_id" GROUP BY "problems"."user_id" ORDER BY "problems"."user_id", uri: postgres:tpitale@localhostdocket_development?adapter=postgres&username=tpitale&password=&host=localhost&database=docket_development&path=docket_development)
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/adapters/dm-do-adapter.rb:20:in execute_reader' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/adapters/dm-do-adapter.rb:20:inblock in aggregate'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:276:in with_connection' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/adapters/dm-do-adapter.rb:14:inaggregate'
from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/repository.rb:8:in aggregate' from /Users/tpitale/.rvm/gems/ruby-1.9.2-p180@docket/gems/dm-aggregates-1.1.0/lib/dm-aggregates/functions.rb:183:inaggregate'
from (irb):1
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 `

'

The SQL generated is strange indeed:

SELECT "problems"."user_id", COUNT("problems"."id") FROM "problems" INNER JOIN "problems" "problems_1" ON "users"."id" = "problems_1"."user_id" GROUP BY "problems"."user_id" ORDER BY "problems"."user_id"

I would expect
SELECT "problems"."user_id", COUNT("problems"."id") FROM "problems", "users" WHERE "users"."id" = "problems"."user_id" GROUP BY "problems"."user_id" ORDER BY "problems"."user_id"

@jpr5
Copy link
Member

jpr5 commented Jun 27, 2011

Isn't :links part of the internal/private API and thus not intended to be manipulated/supported at this level?

What exactly are you trying to do? Why is the :links even necessary?

@tpitale
Copy link
Member Author

tpitale commented Jun 27, 2011

I thought it was part of the query interface. I could be wrong. I was using it to try to intentional join users with problems.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants