基本上我想绕过
def something=(string)
...
end
并做
create!(:something => "direct to database")
出于某种原因,我很难绕过这个功能(我在迁移中使用它)。 感谢
答案 0 :(得分:3)
instance.update_attribute(:something,"direct to database") # bypass validation
或
instance.something = "direct to database"
instance.save(validation = false)
或
sql = "UPDATE models SET something = 'direct to database' WHERE id = #{object.id}"
ActiveRecord::Base.connection.execute(sql)
答案 1 :(得分:2)
model.update_column(:col, 'value')