Reputation: 55
We have models with with before_create triggers like this:
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
Do you think that could be a good idea to move those rails triggers to PostgreSql?
What about performance?
Upvotes: 2
Views: 51
Reputation: 8517
I'll tell you some rules I currently adopt about performance optimizations:
And now the respective considerations:
Upvotes: 0
Reputation: 4837
Using PostgreSQL's after or before insert triggers would definitely be faster and more efficient that Ruby(activerecord) before_create. But your code would become really hard to maintain. Now your softwares business logic would be at two different location 1) store procedure within the rails application 2) In your rails model
Having the two different location would make it hard to debug and program in future.
Upvotes: 1