我使用ENVS列举如下:Rails ActiveRecord update_attributes!不工作
Mysql: 5.1.51-community MySQL Community Server
Rails: 2.3.5
Ruby: 1.8.7
有一个记录,我得到的项目,然后我用下面的代码来更新属性,
item.update_attributes!(
:a => a,
:b => b,
:c => c
)
所有这些更新属性只有字段的值发生了变化,其他属性值保持不变,但我不知道哪些属性发生了更改,所以我更新了所有属性。
在调试过程中,我发现该字段的值发生了变化,这与记录项的值不同,但更新没有任何效果。
有人可以帮我吗?谢谢。
补充:
刚才我跟踪到Rails代码,并且发现该问题与Rails代码此相关的:如果我改变了场分贝值清空
def update(attribute_names = @attributes.keys)
quoted_attributes = attributes_with_quotes(false, false, attribute_names)
return 0 if quoted_attributes.empty?
connection.update(
"UPDATE #{self.class.quoted_table_name} " +
"SET #{quoted_comma_pair_list(connection, quoted_attributes)} " +
"WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}",
"#{self.class.name} Update"
)
end
,然后attribute_names是包含字段a的数组,但db中的值不为空的字段,attribute_names是空数组,但@attributes始终是包含a,b和c的映射。看到rails代码后感到困惑。
没有足够的信息给出 - 我们需要至少该模型能够正确回答这个问题。 – 2011-01-11 13:04:40
我还应该提供哪些信息?谢谢你。 – ywenbo 2011-01-11 13:07:01