I'm using Ruby on Rails.

My code works perfectly fine in the rails console (./script/console). But, when the same exact code is run in my controller, it spits out SQL errors. Here are the errors (log/development.log). The first highlighted line shows what the controller is spitting, while the second highlighted line shows the same code working perfectly fine.

Here's the code in the model:

Code:
has_and_belongs_to_many :contacts, :class_name => 'User', :association_foreign_key => 'contact_id'
Here's the code in the controller:

Code:
@user = User.find(:first)
@user.contacts << @user
And here's some proof that it SHOULD work:

Code:
$ ./script/console
Code:
>> u = User.create
=> #<User:0x22d66b4 @attributes={"id"=>1, "avatar_id"=>nil, "first_name"=>nil, "last_name"=>nil, "password"=>nil, "login"=>nil, "middle_name"=>nil}, @errors=#<ActiveRecord::Errors:0x22d6074 @errors={}, @base=#<User:0x22d66b4 ...>>, @new_record_before_save=false, @new_record=false>
Code:
>> u.contacts_count
=> 0
Code:
>> u.contacts << u
=> [#<User:0x22d66b4 @contacts=[...], @attributes={"id"=>1, "avatar_id"=>nil, "first_name"=>nil, "last_name"=>nil, "password"=>nil, "login"=>nil, "middle_name"=>nil}, @errors=#<ActiveRecord::Errors:0x22d6074 @errors={}, @base=#<User:0x22d66b4 ...>>, @new_record_before_save=false, @new_record=false>]
Code:
>> u.contacts_count
=> 1
Somebody please help me. Otherwise, I think I just might have a stroke.