title: Invalid single-table inheritance type .. is not a subclass of
body: <p>I am trying to record each purchase a user makes through a many-to-many relationship between Users and Transactions and link them through a join table "transactuins_users". But I have two problems, first, I am required to supply the create! method with the object it is called upon's id, I thought that Rails was supposed to figure this out by itself given the association.</p>
  
  <p>Furthermore, whenever I call the purchase method, I receive an error "Invalid single-table inheritance type: buy is not a subclass of Transaction"</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
    # Associations
    has_and_belongs_to_many :transactions
  
    def purchase(package)
      return false unless funds_available?(package) and !owns?(package)
        package.with_lock do
  
        # Makes transaction
        package.user_id = id
        package.save!
        withdraw(package.cost)
  
        # Records transaction
        values = {user_id: id, type: "buy", cost: package.cost}
        transactions.create values
      end
    end
  
  
  class Transaction &lt; ActiveRecord::Base
  
    # Associations 
    has_and_belongs_to_many :transactions
  
    # Validations
    validates :user_id, :cost, presence: true
  </code></pre>