连接表的 Rails 命名约定 [英] Rails naming convention for join table
问题描述
这个问题源于:如何在创建后链接表单rails 连接表
我正在创建我的产品和类别模型之间的连接表.
I am creating the join table between my Product and Category Models.
连接表应该取什么名字?category_products 或 category_products 或其他什么?
What should the join table be named? categories_products or category_products or something else?
推荐答案
categories_products
.都是复数.按词汇顺序.
categories_products
. Both plural. In lexical order.
引用:
除非通过使用显式指定连接表的名称:join_table 选项,Active Record 通过使用类名的词法顺序.所以客户和订单之间的连接模型将给出默认的连接表名称customers_orders"因为c"在词法排序中比o"高.
Unless the name of the join table is explicitly specified by using the :join_table option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering.
这篇关于连接表的 Rails 命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!