activerecord, refactoring the source code
class User &lt; AR::Base
  has_many :lexemes, :dependent =&gt; :destroy
  has_many  :words, :through =&gt; :lexemes
end

class Lexeme &lt; AR::Base
  belongs_to :user
  belongs_to :word
end

class Word &lt; AR::Base
  has_many :lexemes
  has_many :users, :through =&gt; :lexemes
end


You should normally be able to create word by following code but it seems there is a bug in Rails.

word = @user.words.find_or_create_by_word(token)


Therefore I have changed the model to following. You may remove it when the bug is fixed.

class User &lt; ActiveRecord::Base
  has_many :lexemes
  has_many :words, :through =&gt; :lexemes do
        def find_or_create_by_word(token)
            find_by_word(token) || create(:word =&gt; token)
        end
  end
end