How to write directly to database with rails
Basically i would like to bypass
def something=(string)
...
end
and do
create!(:something => "direct to database")
For some reason I'm having a hard time bypassing this fu开发者_JAVA百科nction (i'm using this inside a migration). Thanks
instance.update_attribute(:something,"direct to database") # bypass validation
Or
instance.something = "direct to database"
instance.save(validation = false)
Or
sql = "UPDATE models SET something = 'direct to database' WHERE id = #{object.id}"
ActiveRecord::Base.connection.execute(sql)
model.update_column(:col, 'value')
精彩评论