In both models, Active Record would normally assume each table has
a field labeled type, which stores the inheritance information. However, in the first model, we
CHAPTER 7 ?– WORKING WITH LEGACY SCHEMA 171
say to use account_type as the inheritance column, and in the second model, we use a block to
assign the name of the inheritance column:
# Using the set_table_name method
require 'rubygems'
require_gem 'activerecord'
ActiveRecord::Base.establish_connection(:adapter => "sqlserver",
:host => "localhost", :username => "sa", :password => "", :database => "testdb")
class Account < ActiveRecord::Base
set_inheritance_column "account_type"
end
class Reader < Account
end
puts Reader.find(1).inspect
class Comment < ActiveRecord::Base
set_primary_key {
d = ["comm","ents","_category"]
d.join
}
end
class Storycomment < Comment
end
puts Storycomment.find(1).inspect
set_sequence_name
This is a method that you can use within a model to specify the name of the sequence
Active Record should use to generate id values for primary keys.
Pages:
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391