This project is archived and is in readonly mode.
AR.count - Using symbol in :group with :join fails to return proper column
-
CancelProfileIsBroken
- Tag changed from active_record, count, group, group_field, join, table_name to active_record, bugmash, count, group, group_field, join, table_name
-
dira
- Tag changed from active_record, bugmash, count, group, group_field, join, table_name to active_record, bugmash, count, group, group_field, join, patch, table_name
I have attached a patch with tests and implementation.
-
Christopher Hlubek
Dira: I tested your patch today and found that the SQL in the new tests doesn't work with PostgreSQL and SQLite. The test did work with MySQL though.
Another thing I found was the redefinition of the test method "test_should_sum_field" that seems to be useless.
The errors in PostgreSQL and SQlite were the following:
PostgreSQL
{mkd-extraction-2cdae367fc573288e8154f028fda606c}
1) Error: test_should_calculate_grouped_association_with_self_association_and_count_on_field_name(CalculationsTest):
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near ")"
LINE 1: ...ource_id FROM "edges" INNER JOIN (edges AS second) ON (edge...: SELECT count("edges".source_id) AS count_source_id, "edges".source_id AS edges_source_id FROM "edges" INNER JOIN (edges AS second) ON (edges.sink_id = second.source_id ) GROUP BY "edges".source_id
{mkd-extraction-8a16f59ae20e40ff40fa2c1f8adb5d6c}2) Error: test_should_calculate_grouped_association_with_self_association_and_count_on_full_field_name(CalculationsTest):
{mkd-extraction-2cdae367fc573288e8154f028fda606c}
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near ")"
LINE 1: ...ource_id FROM "edges" INNER JOIN (edges AS second) ON (edge...: SELECT count(second.source_id) AS count_second_source_id, second.source_id AS second_source_id FROM "edges" INNER JOIN (edges AS second) ON (edges.sink_id = second.source_id ) GROUP BY second.source_id
{mkd-extraction-512a34c6016ffa7918514c390b738fb2}SQLite3
{mkd-extraction-a916f19abb37361a398d56b0954d724a}
1) Error: test_should_calculate_grouped_association_with_self_association_and_count_on_field_name(CalculationsTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: second.source_id: SELECT count("edges".source_id) AS count_source_id, "edges".source_id AS edges_source_id FROM "edges" INNER JOIN (edges AS second) ON (edges.sink_id = second.source_id ) GROUP BY "edges".source_id2) Error: test_should_calculate_grouped_association_with_self_association_and_count_on_full_field_name(CalculationsTest):
{mkd-extraction-1f8406fc6a3a5eaadb6c748538d51476}
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: second.source_id: SELECT count(second.source_id) AS count_second_source_id, second.source_id AS second_source_id FROM "edges" INNER JOIN (edges AS second) ON (edges.sink_id = second.source_id ) GROUP BY second.source_idSo it seems that your
INNER JOINalias is not understood in these DBs (and is a syntax error in PostgreSQL).I'm not a PostgreSQL or SQLite3 expert, but it seems you example is very limited to MySQL.
-
dira
Hi Christopher,
thanks for your feedback. Indeed I tested only on MySQL as I did not have the other databases installed :|
My Postgres installation is still in progress - but I fixed the tests to be compatible with generic SQL syntax and they pass on sqlite.
Could you please verify the patch again? Thank you.
-
Christopher Hlubek
+1 from me, as it works in MySQL, PostgreSQL and SQLite3 now on Rails master
BTW, I used the RailsBridge Bugmash VM (http://greg.nokes.name/2009/10/05/railsbridge-bugmash-vm/) that is preconfigured with the databases (except the grants were wrong for MySQL and PostgreSQL) for testing
-
dira
Cool, thanks for the link!
-
Rizwan Reza
- Tag changed from active_record, bugmash, count, group, group_field, join, patch, table_name to active_record, count, group, group_field, join, patch, table_name
-
Santiago Pastorino
- State changed from new to open
- Importance changed from to
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
