导轨 3.2.3
这是让我感到困惑的例子:
class Person < ActiveRecord::Base
has_many :toys
end
class Man < Person
end
class Woman < Person
has_many :cookies, foreign_key: person_id
end
然后会发生这种情况:
Person.reflections.keys # [:toys]
Man.reflections.keys # [:toys]
Woman.reflections.keys # [:cookies]
请注意,我预计Woman.reflections.keys
会[:toys, :cookies]
此外,如果我这样做:
Person.new.keys # []
Man.new.keys # []
Woman.new.keys # NoMethodError: undefined method `association_class' for nil:NilClass