Can a class have the association has_itself?

is it possible to implement a recursive foreign key association like
that?

i’m writing a vocab app, where i want the vocab table to have an id
and two foreign keys, word1 and word2.
the word table will have an id, a word-string, and a language

i’m trying to do this as follows:

class Vocab < ActiveRecord::Base
belongs_to :word
belongs_to :word

class Word < ActiveRecord::Base
has_many :vocabs
has_many :words, :through => :vocabs

but it doesn’t work. I’m really new to rails and ruby.

not that way :slight_smile:

Vocab must have two word fields (eg the default word_id and word_two_id)

class Vocab …
belongs_to :word
belongs_to :word_two, :foreign_key => :word_two_id

class Word …
has_many :vocabs # referencing the first belongs_to on word_id
has_many :vocab_twos, :foreign_key => :word_two_id # only if you need
it…

has_many :words, :through => :vocabs # or :vocab_twos

not 100% sure that’s exact, but something on that line…