今天在做开发的时候遇到一个莫名奇妙的问题,后来才发现是表中有字段名字叫type引起的,还是在http://dev.rubyonrails.org/ticket/7998 上发现原来是rails的一个bug,发出来,免得大家遇到相同的问题。
Ticket #7998 (new defect)
Opened 2 months ago
Last modified 2 weeks ago
Scafford should detect & report error when DB field named 'type'
| Reported by: | dlamet | Assigned to: | core |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.x |
| Component: | ActiveRecord | Version: | edge |
| Severity: | normal | Keywords: | field name error tINTEGER |
| Cc: |
Description ¶
When generating a scaffold, it will accept a table that has a field named type. This causes a crypic error inside base.rb:
compile error c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1358: syntax error, unexpected tINTEGER Object::1
It would save a lot of people (like me) a lot of time if the scaffold code would fail with a useful error about the field name being 'type'.
本文记录了一个在使用Rails进行开发时遇到的问题,即当数据库表中存在名为'type'的字段时,会导致编译错误。文章指出这是一个已知的Rails缺陷,并建议在生成scaffold时应检查并报告此类错误。
2万+

被折叠的 条评论
为什么被折叠?




I would like to second that. I just came across the exact same problem and for a newbie it can be really a cumbersome issue.
A warning should be used whenever a field name type exists. Better yet, it shouldn't be a problem at all.