开发者

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')

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜