このコードを考えると:
class Word < ActiveRecord::Base
has_and_belongs_to_many :definitions
end
class Definition < ActiveRecord::Base
has_and_belongs_to_many :word
validates :word, presence: true
end
mysql> show columns from definitions_words;
+---------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+-------+
| definition_id | int(11) | NO | PRI | NULL | |
| word_id | int(11) | NO | PRI | NULL | |
+---------------+---------+------+-----+---------+-------+
私が電話するとき:
word = Word.first
word.definitions.create!
私は得る:
ActiveRecord::RecordInvalid (Validation failed: Word can't be blank)