Hi there, I am working through a tutorial and I'm at the point of
accepting or declining a friend request.
However, whenever I click accept of decline, I get the following
error:
Mysql::Error: Column 'created_at' in order clause is ambiguous: SELECT
`users`.id FROM `users` INNER JOIN `friendships` ON `users`.id =
`friendships`.friend_id WHERE (`users`.`id` = 115) AND
((`friendships`.user_id = 114) AND ((status = 'requested'))) ORDER BY
created_at LIMIT 1
I've looked through the controller for these 2 actions, but nothing
stands out.
Either in your User has_many :friendships declaration or the User.find
that joins :friendships in the controller you have :order =>
"created_at". The RDBMS can't know which table to use for created_at
column, as both have one. You need to specify that.
>
>
>
>
>
> > Hi there, I am working through a tutorial and I'm at the point of
> > accepting or declining a friend request.
>
> > However, whenever I click accept of decline, I get the following
> > error:
>
> > Mysql::Error: Column 'created_at' in order clause is ambiguous: SELECT
> > `users`.id FROM `users` INNER JOIN `friendships` ON `users`.id =
> > `friendships`.friend_id WHERE (`users`.`id` = 115) AND
> > ((`friendships`.user_id = 114) AND ((status = 'requested'))) ORDER BY
> > created_at LIMIT 1
>
> > I've looked through the controller for these 2 actions, but nothing
> > stands out.
>
> > Please can anyone suggest how to fix this?
>
> > Many Thanks
>
> Either in your User has_many :friendships declaration or the User.find
> that joins :friendships in the controller you have :order =>
> "created_at". The RDBMS can't know which table to use for created_at
> column, as both have one. You need to specify that.
This is an error in the SQL statement being generated. The created_at
column exists in both the Users and Friendships tables. You need to
indicate the table of the column you want to order by.