Forum: Ruby on Rails polymorphism + inheritance

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Peter E. (Guest)
on 2006-03-27 16:19
(Received via mailing list)

currently I do some work with polymorphic associations in egde rails

class Order < ActiveRecord::Base
  belongs_to :payment, :polymorphic => true

class CreditCardPayment < Payment

class PayPalPayment < Payment

class Payment < ActiveRecord::Base
  has_one :order, :as => :payment
  # common stuff in here

I want to use [Payment] for common functionality typical to payments.

However, this will throw an error:
>> CreditCardPayment.create(...)
ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table
doesn't exist: SHOW FIELDS  FROM payments

Is there a way to convince ActiveRecord that [Payment] is an abstract
class that does not need to exist (and take the name of the concrete
for determining the table name) ?

Thanks in advance!!

Best regards
Don W. (Guest)
on 2006-03-27 20:29
(Received via mailing list)
Looks like you're trying to use single table inheritance here.

This requires a "payments" table with a "type" column for storing the
class of the row ("CreditCardPayemnt" or "PayPalPayement" or ...)
This topic is locked and can not be replied to.