Actions
Defect #42622
closedJoining both atom_token and api_token on the User model causes an error due to the ambiguous column name "action"
Start date:
Due date:
% Done:
0%
Estimated time:
Resolution:
Fixed
Affected version:
Description
When using JOINs with the User model, if both atom_token
and api_token
are utilized like this:
User.joins(:atom_token, :api_token)
then this error results:
#<ActiveRecord::StatementInvalid:"PG::AmbiguousColumn: ERROR: column reference \"action\" is ambiguous\nLINE 1: ... \"api_tokens_users\".\"user_id\" = \"users\".\"id\" AND (action='ap...\n
This can be fixed by prepending the proper table name in the `where` clause on these lines, 92 and 93 in user.rb:
has_one :atom_token, lambda {where "#{table.name}.action='feeds'"}, :class_name => 'Token'
has_one :api_token, lambda {where "#{table.name}.action='api'"}, :class_name => 'Token'
(Note that all that is being added here is
#{table.name}.
)
When doing this then the resulting SQL turns into:
SELECT "users".* FROM "users" INNER JOIN "tokens" ON "tokens"."user_id" = "users"."id" AND (tokens.action='feeds') INNER JOIN "tokens" "api_tokens_users" ON "api_tokens_users"."user_id" = "users"."id" AND (api_tokens_users.action='api') WHERE "users"."type" = $1
I have no idea how to create a pull request with SVN to provide this fix, so if someone could do this then awesome :)
Files
Updated by Go MAEDA 5 days ago
- File 42622.patch 42622.patch added
- Subject changed from "PG::AmbiguousColumn: ERROR: column reference \"action\" is ambiguous" to Joining both atom_token and api_token on the User model causes an error due to the ambiguous column name "action"
- Status changed from New to Confirmed
- Target version set to 5.1.9
Thank you for reporting the issue and suggesting the fix.
I am setting the target version to 5.1.9.
Updated by Marius BĂLTEANU 5 days ago
Lorin Thwaits wrote:
I have no idea how to create a pull request with SVN to provide this fix, so if someone could do this then awesome :)
Unfortunately, you can't create a pull request, you need to post it as a patch / diff.
Actions