0

We had the following class to process SOAP responses from external API(s) which worked fine in ruby 1.8.7, but it is looking for a table with these columns post migration (which has never been there) to ruby 1.9.2/rails 3.1, How do I handle this migratation?

class SoapResponse < ActiveRecord::Base 
  def self.columns
    @columns ||= [];
  end

  def self.column(name, sql_type = nil, default = nil, null = true)
    columns << ActiveRecord::ConnectionAdapters::Column.new(
      name.to_s, default, sql_type.to_s, null)
  end

  def save(validate = true)
    validate ? valid? : true
  end

  column :soap_payload, :text
  serialize :soap_payload
end
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
Sam
  • 8,387
  • 19
  • 62
  • 97

2 Answers2

3

You don't (have any migrations for it).

You don't have migrations and you don't inherit from ActiveRecord::Base as that is the database ORM component.

If you use a generator to create the model use --skip-migration to avoid generating the database migration file.

You can still get validations and conversions though, e.g.

class SoapResponse
  include ActiveModel::Validations
  include ActiveModel::Conversion

If you want some setup data (i.e. Constants, given there is no db! ) you can just define them here (Constants start with uppercase).

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
1

I guess you want the serialization capability of ActiveRecord::Base. That seems to be the only thing this class is using it for. If so, try calling this in your class definition:

self.abstract_class = true

Or you could try using ActiveModel::Serialization.

The pattern in your code looks like what's suggested in this answer for table-less AR models in Rails 2.

Community
  • 1
  • 1
rkb
  • 3,442
  • 19
  • 25