私は次のようなモデルを持っています
class CqmExternalId < ActiveRecord::Base
set_table_name :cqm_external_id
has_many :ipp_measure_ids, :class_name => "CqmMeasureId", :foreign_key => "cqm_external_id", :conditions => [" name = 'IPP'"]
has_many :numer_measure_ids, :class_name => "CqmMeasureId", :foreign_key => "cqm_external_id", :conditions => [" name = 'NUMER'"]
has_many :denom_measure_ids, :class_name => "CqmMeasureId", :foreign_key => "cqm_external_id", :conditions => [" name = 'DENOM'"]
has_many :denex_measure_ids, :class_name => "CqmMeasureId", :foreign_key => "cqm_external_id", :conditions => [" name = 'DENEX'"]
end
class CqmMeasureId < ActiveRecord::Base
set_table_name :cqm_measure_id
belongs_to :cqm_external, :class_name => "cqm_external", :foreign_key => "cqm_external_id"
end
ipp_measure_ids
デフォルト値を挿入するための関連付けの作成方法create
c = CqmExternalId.first
c.ipp_measure_ids.create!(:key=>"ABC-1234") => #<CqmMeasureId id: 1, name:nil, key:"ABC-1234>"
# I want the name attribute to be initialized automatically as "IPP"