I know type
is a magic field name with ActiveRecord
for use in Single Table Inheritance. But :type
is not included in Mongoid.destructive_fields
. Is there any reason I can't use it as a field name? Upload.upload_type
feels so ackward and I'd much prefer to use Upload.type
.
我知道type是一个具有ActiveRecord的神奇字段,用于单表继承。但是:类型不包含在mongodb . distive_fields中。有什么理由我不能用它作为字段名?上传。upload_type感觉非常糟糕,我更喜欢使用Upload.type。
Furthermore class
, category
, and variety
don't seem like good alternatives.
此外,阶级、类别和多样性似乎不是好的选择。
3 个解决方案
#1
2
I am using it without any problems so far. So unless I run into any issues down the road I'm going to answer no, there's no reason to avoid using the word "type".
到目前为止,我没有遇到任何问题。所以,除非我遇到任何问题,否则我将回答“不”,没有理由不使用“类型”这个词。
#2
0
In Mongoid an attribute _type
is define to help in the STI too. So it's better to avoid using it too.
在Mongoid属性中,_type也被定义为帮助STI。所以最好避免使用它。
#3
0
You are correct that "_type" is used for STI and thus "type" is technically a valid attribute name. It will work for your situation just fine. I would just be cautious using those "special names", however. If you ever switch over to a different database you will probably run into problems, but if you have control over that and know that you'll be using MongoDB, then there isn't a really good reason why you can't use the "type" field.
您是正确的,STI使用“_type”,因此“type”在技术上是一个有效的属性名。这对你的情况很好。不过,我会谨慎地使用这些“特殊的名字”。如果您切换到另一个数据库,您可能会遇到问题,但是如果您能够控制它并知道您将使用MongoDB,那么就没有一个很好的理由不能使用“type”字段。
I personally would not use any of the special words that many databases or frameworks use, as it just makes it less-confusing for others. But that is just a personal preference; there's no technical reason.
我个人不会使用许多数据库或框架所使用的任何特殊词汇,因为这只会让其他人更容易理解。但这只是个人偏好;没有技术的原因。
#1
2
I am using it without any problems so far. So unless I run into any issues down the road I'm going to answer no, there's no reason to avoid using the word "type".
到目前为止,我没有遇到任何问题。所以,除非我遇到任何问题,否则我将回答“不”,没有理由不使用“类型”这个词。
#2
0
In Mongoid an attribute _type
is define to help in the STI too. So it's better to avoid using it too.
在Mongoid属性中,_type也被定义为帮助STI。所以最好避免使用它。
#3
0
You are correct that "_type" is used for STI and thus "type" is technically a valid attribute name. It will work for your situation just fine. I would just be cautious using those "special names", however. If you ever switch over to a different database you will probably run into problems, but if you have control over that and know that you'll be using MongoDB, then there isn't a really good reason why you can't use the "type" field.
您是正确的,STI使用“_type”,因此“type”在技术上是一个有效的属性名。这对你的情况很好。不过,我会谨慎地使用这些“特殊的名字”。如果您切换到另一个数据库,您可能会遇到问题,但是如果您能够控制它并知道您将使用MongoDB,那么就没有一个很好的理由不能使用“type”字段。
I personally would not use any of the special words that many databases or frameworks use, as it just makes it less-confusing for others. But that is just a personal preference; there's no technical reason.
我个人不会使用许多数据库或框架所使用的任何特殊词汇,因为这只会让其他人更容易理解。但这只是个人偏好;没有技术的原因。