eallik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-05 22:54 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
eallik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-06 00:13 UTC
Re: DB trigger vs before_create
Yes, but the standard Rails practice is also to use fixtures for testing, but putting that logic into models means no fixtures. On May 6, 2:45 am, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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. > > -- > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On May 6, 8:13 am, "eal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <eal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, but the standard Rails practice is also to use fixtures for > testing, but putting that logic into models means no fixtures. > > On May 6, 2:45 am, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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. > > > -- > > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---