The api docs for ActiveRecord::Associations::ClassMethods describe how
you specify associations between your models, including overriding the
default foreign key and class name when you don’t follow rails’ naming
Is this a bad idea anyway?
There are lots of sound reasons for referring to the same table
multiple times from a single row.
It could also mean that your FK is in the wrong table, if you’re
just trying to model a one-to-many relationship.
Just guessing from your model names but it appears that you are
building a “reflexive many-to-many relationship.” Reflexive meaning
that you are creating a join table between two rows of a single table:
User <------->> Friend <<-------> User
An excerpt from “Rails Recipies” shows this type of Self Referential
class AddPeopleAndTheirFriendsRelationship < ActiveRecord::Migration
create_table :people do |t|
t.column “name”, :string
create_table :friends_people, :id => false do |t|
t.column “person_id”, :integer
t.column “friend_id”, :integer
and the Person model looks like:
class Person < ActiveRecord::Base
:class_name => “Person”,
:join_table => “friends_people”,
:association_foreign_key => “friend_id”,
:foreign_key => “person_id”
By the way, I would likely model this with the join table as a
separate resource using has_many_through. I would call the joining
resource Friend. This way you can store information about the
association in the Friend model. Such as in your case with :ready =>
boolean. Or things like friendship_established_on and other such
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.