我想获得一个模型关联的列表:accepts_nested_attributes_for
。例如,我想[:children, :other_children]
从这个模型中得到:
class ParentResource < ActiveRecord::Base
has_many :children
has_many :other_children
has_many :non_nested_children
accepts_nested_attributes_for :children, :other_children
end
现在,我正在使用以下功能进行此操作:
def self.nested_associations
reflect_on_all_associations.map(&:name).select do |association_name|
association_name if method_defined?("#{association_name}_attributes=".to_sym)
end
end
但是我感到有一种获取此数组的嵌入式方法。如果是这样,什么是正确的方法。
我不确定这是否是“正确的方法”,但您不能这样做:
ParentResource.nested_attributes_options.keys
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句