ruby-on-rails – 覆盖has_many关系的模型名称
发布时间:2020-12-17 03:52:33 所属栏目:百科 来源:网络整理
导读:如果有更优雅的方式,这将是很好的,给定这些模型: @forum_topic = ForumTopic.find(1)@forum_topic.forum_sub_topics.each do |fst| #it would be nicer if one could just type @forum_topic.sub_topics.each... #end 在sub_topics前面包含forum_似乎是多余
如果有更优雅的方式,这将是很好的,给定这些模型:
@forum_topic = ForumTopic.find(1) @forum_topic.forum_sub_topics.each do |fst| #it would be nicer if one could just type @forum_topic.sub_topics.each... # end 在sub_topics前面包含forum_似乎是多余的,因为我知道我正在处理一个forum_topic.我可以将表/模型的名称更改为SubTopic,但这有点通用,可能会出现在应用程序的某个位置.有没有办法覆盖在ForumTopic上为has_many关联创建的方法的名称? 楷模: class ForumTopic... has_many :forum_sub_topics end class ForumSubTopic... end 答案就在这里啊.谢谢! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |