有没有办法从Sequel模型中获取JUST SQL语句?
class Asset < Sequel::Model(:Asset)
set_primary_key :id
many_to_one :site, key: :siteid
many_to_one :company, key: :companyid
def validate
super
errors.add(:partnumber, "can't be empty") if partnumber.nil? || partnumber.empty?
errors.add(:serialnumber, "can't be empty") if serialnumber.nil? || serialnumber.empty?
errors.add(:description, "can't be empty") if description.nil? || description.empty?
end
end
asset = Asset.new
# Add values to asset
puts asset.insert_sql
答案 0 :(得分:2)
尝试
puts Asset.dataset.insert_sql
实际插入(默认)值。
或
puts Asset.dataset.insert_sql(asset.values)
如果您已经准备好了实例。不确定你是否记得这个?
有关详情,请参阅Sequel::Dataset文档和Sequel's mass assignment guide。