浏览 4008 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
作者 | 正文 | ||||||||||
发表时间:2007-06-14
今天在做开发的时候遇到一个莫名奇妙的问题,后来才发现是表中有字段名字叫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'
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'. Change History声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|||||||||||
返回顶楼 | |||||||||||
发表时间:2007-06-14
像type和name之类的有可能是关键字的词还是少用为好。
|
|||||||||||
返回顶楼 | |||||||||||
发表时间:2007-06-15
type记得是rails数据库魔法的一个小tricky,你用来干其他事情了。估计就出错了。
|
|||||||||||
返回顶楼 | |||||||||||
发表时间:2007-06-15
好像通过 product.attributes[:type] 可以访问
|
|||||||||||
返回顶楼 | |||||||||||
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.