Mysql Error

Hello. I was working on a add friend function. Buts i get an mysql error.

Mysql::Error: #23000Column 'created_at' in order clause is ambiguous: SELECT `users`.id FROM `users` INNER JOIN friendships ON users.id = friendships.friend_id WHERE (`users`.`id` = 2) AND ((`friendships`.user_id = 1) AND ((status = 'requested'))) ORDER BY created_at LIMIT 1

Extracted source (around line #9):

6: form_tag "/#{controller.controller_name}/#{logged_user ? 'logout' : 'login'}" do %> 7: 8: <% if logged_user %> 9: <% unless @user == current_user || current_user.requested_friends.include?(@user) || current_user.friends.include?(@user) || current_user.pending_friends.include?(@user) %> 10: <% form_for(:friendship, :url => user_friends_path(:user_id => current_user.id, :friend_id => @user.id)) do |f| %> 11: <%= submit_tag "Lägg till som vän" %> 12:

Hello. I was working on a add friend function. Buts i get an mysql error.

Mysql::Error: #23000Column 'created_at' in order clause is ambiguous: SELECT `users`.id FROM `users` INNER JOIN friendships ON users.id = friendships.friend_id WHERE (`users`.`id` = 2) AND ((`friendships`.user_id = 1) AND ((status = 'requested'))) ORDER BY created_at LIMIT 1

well at the point where you've written :order => 'created_at' you need
to say 'users.created_at' or 'friendships.created_at'

Fred