从创建之前移动到PostgreSql触发器?
我们有这样的模型,在创建触发器之前:从创建之前移动到PostgreSql触发器?,sql,ruby-on-rails,postgresql,Sql,Ruby On Rails,Postgresql,我们有这样的模型,在创建触发器之前: def set_location_id self.location_id = Location.find_by(code: location_code).id end def set_product_id self.product_id = Product.find_by(code: product_code).id end 您认为将这些rails触发器移动到PostgreSql是一个好主意吗 性能如何?使用PostgreSQL的after或be
def set_location_id
self.location_id = Location.find_by(code: location_code).id
end
def set_product_id
self.product_id = Product.find_by(code: product_code).id
end
您认为将这些rails触发器移动到PostgreSql是一个好主意吗
性能如何?使用PostgreSQL的after或before insert触发器肯定比Ruby(activerecord)创建之前更快、更高效。但是你的代码会变得很难维护。现在,您的软件业务逻辑将位于两个不同的位置 1) 在rails应用程序中存储过程 2) 在rails模型中
拥有两个不同的位置将使将来调试和编程变得困难 我将告诉您一些我目前采用的关于性能优化的规则: