DB trigger vs before_create

Hello everyone,

I'm having trouble figuring out which approach is better.
I have the following tables: products, orders and line_items.
Every time an Order is placed, the quantity field in the products
table has to be updated for each LineItem in the Order. One option is
to use DB triggers which is not as portable as using before_create in
the Order model. But with before_create I cannot use fixtures for
orders and line_items since they don't use before_create as models do.

Has anyone any recommendations on which approach is better?

Erik

But with before_create I cannot use fixtures for
orders and line_items since they don't use before_create as models do.

Er... What?

The standard rails practice is to put the logic in your models. I
find code like this is easier to write, maintain, and test.

Yes, but the standard Rails practice is also to use fixtures for
testing, but putting that logic into models means no fixtures.

Not quite... fixtures are "fixed" pieces of data that you test your
models and controllers against. You need to make sure they always fit
your business rules even as they change.

Fixtures are not meant for testing your validation methods. You
should use unit tests for that.