开发者

How to write directly to database with rails

开发者 https://www.devze.com 2023-04-13 07:45 出处:网络
Basically i would like to bypass def something=(string) ... end and do create!(:something => \"direct to database\")

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

精彩评论

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