Skip to content

Instantly share code, notes, and snippets.

@tiagoamaro
Created January 13, 2015 23:38
Show Gist options
  • Select an option

  • Save tiagoamaro/49465ee23a1924cb15df to your computer and use it in GitHub Desktop.

Select an option

Save tiagoamaro/49465ee23a1924cb15df to your computer and use it in GitHub Desktop.
Rails many-to-many self-join
# as described in http://guides.rubyonrails.org/association_basics.html#self-joins
class User < ActiveRecord::Base
has_and_belongs_to_many :friends,
class_name: "User",
foreign_key: "this_user_id",
association_foreign_key: "other_user_id"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment