composite_primary_keysではvarcharがダメなの?
とりあえずテストケースをざーっと読んでみた。set_primary_keysを使っているのは以下の四つ。クラスとDDLをセットで挙げます。
class ProductTariff < ActiveRecord::Base set_primary_keys :product_id, :tariff_id, :tariff_start_date belongs_to :product, :foreign_key => :product_id belongs_to :tariff, :foreign_key => [:tariff_id, :tariff_start_date] end
CREATE TABLE `product_tariffs` ( `product_id` int(11) NOT NULL, `tariff_id` int(11) NOT NULL, `tariff_start_date` date NOT NULL, PRIMARY KEY (`product_id`,`tariff_id`,`tariff_start_date`) ) TYPE=InnoDB;
class ReferenceCode < ActiveRecord::Base set_primary_keys :reference_type_id, :reference_code belongs_to :reference_type, :foreign_key => "reference_type_id" validates_presence_of :reference_code, :code_label, :abbreviation end
CREATE TABLE `reference_codes` ( `reference_type_id` int(11) NOT NULL, `reference_code` int(11) NOT NULL, `code_label` varchar(50) default NULL, `abbreviation` varchar(50) default NULL, `description` varchar(50) default NULL, PRIMARY KEY (`reference_type_id`,`reference_code`) ) TYPE=InnoDB;
class Suburb < ActiveRecord::Base set_primary_keys :city_id, :suburb_id has_many :streets, :foreign_key => [:city_id, :suburb_id] end
CREATE TABLE `suburbs` ( `city_id` int(11) NOT NULL, `suburb_id` int(11) NOT NULL, `name` varchar(50) NOT NULL, PRIMARY KEY (`city_id`,`suburb_id`) ) TYPE=InnoDB;
class Tariff < ActiveRecord::Base set_primary_keys [:tariff_id, :start_date] has_many :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date] has_one :product_tariff, :foreign_key => [:tariff_id, :tariff_start_date] has_many :products, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date] end
CREATE TABLE `tariffs` ( `tariff_id` int(11) NOT NULL, `start_date` date NOT NULL, `amount` integer(11) default NULL, PRIMARY KEY (`tariff_id`,`start_date`) ) TYPE=InnoDB;
というわけで、intとdateはオッケーだけど、PKにvarcharダメなんじゃねーの疑惑が発生。この疑惑を現在調査中。