且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过尚未保存的父关联访问ActiveRecord祖父母关联?

更新时间:2023-01-20 13:58:35

请查看:inverse_of 选项> 属于 has_many 。在不同情况下构建和获取关联记录时,此选项将处理双向分配。

Please look into the :inverse_of option for belongs_to and has_many. This option will handle two-way assignments when building and fetching associated records in different cases.

来自双向关联,用于 ActiveRecord :: Associations :: ClassMethods 在文档中:


在关联上指定:inverse_of 选项可让您告诉Active Record逆关系,它将优化对象加载。

Specifying the :inverse_of option on associations lets you tell Active Record about inverse relationships and it will optimise object loading.