Exception: ActiveRecord::FixtureSet::TableRow::PrimaryKeyError

Inherits:
StandardError
  • Object
show all
Defined in:
activerecord/lib/active_record/fixture_set/table_row.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(label, association, value) ⇒ PrimaryKeyError

Returns a new instance of PrimaryKeyError.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'activerecord/lib/active_record/fixture_set/table_row.rb', line 43

def initialize(label, association, value)
  super(<<~MSG)
    Unable to set #{association.name} to #{value} because the association has a
    custom primary key (#{association.join_primary_key}) that does not match the
    associated table's primary key (#{association.klass.primary_key}).

    To fix this, change your fixture from

    #{label}:
      #{association.name}: #{value}

    to

    #{label}:
      #{association.foreign_key}: **value**

    where **value** is the #{association.join_primary_key} value for the
    associated #{association.klass.name} record.
  MSG
end