[英]Ruby on Rails working with pre-existing database. Rails makes everything plural
What is the deal with this? 这有什么关系? I'm working with a pre-existing that I did not do myself.
我正在处理一个我没有做过的预先存在的事情。 Everything in the database is labeled in singular form.
数据库中的所有内容都以单数形式标记。 user, security, spec, etc. I guess the right way would be users, securities, specs.
用户,安全,规格等我认为正确的方式将是用户,证券,规格。 At least that's what ruby on rails try's to lookup when I generate a scaffold .
至少那就是当我生成一个脚手架时,ruby on rails尝试查找。
How do I specifically state to use user instead of users in the sql. 我如何明确声明在sql中使用用户而不是用户。 I don't see anywhere in my project where it is looking up the sql.
我在项目的任何地方都没有看到它在查找sql。 I mean if my model is user you would think it would try to lookup user.
我的意思是如果我的模型是用户,你会认为它会尝试查找用户。 Instead of users.
而不是用户。
Thanks for any help. 谢谢你的帮助。
You need set_table_name :name_of_the_table
in your model ( source ). 您需要在模型中使用
set_table_name :name_of_the_table
( source )。
So: 所以:
class User < ActiveRecord::Base
set_table_name :user
end
The reason they use plural for the table and singular for the model is because an instance of the model represents one user, whereas the table contains all the users. 他们为表使用复数而对模型使用单数的原因是因为模型的实例代表一个用户,而表包含所有用户。 It's just to make it more readable and logical.
只是为了使它更具可读性和逻辑性。
You can specifiy the table name: 您可以指定表名:
How do I explicitly specify a Model's table-name mapping in Rails? 如何在Rails中显式指定Model的表名映射?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.