On Tue, May 19, 2009 at 10:42 AM, Jamie van Dyke <[email protected]> wrote:
> > On 19 May 2009, at 10:39, Francis Fish wrote: > > > > > This will find or create a progress called offer and set its > > received date. Very happy with this because it makes what the code > > is doing explicit. > > > > Out of curiosity, why not use the built in find_or_create_by methods? > > Train wreck, which find_or_create is very good at creating IMHO, e.g.: cp = claim.claim_progresses.find_or_create_by_progress(claim.my_progress(Progress.offer)) cp.date_received ||= Time.now cp.save # Plus a comment saying what the intention is and a nightmare to set up the expectations vs cp = claim.offer_progress_received # REALLY easy to spec up my_progress gets the appropriate one for the claim type. (unless you want Progress.offer.find_by_claim_type(claim.claim_type) just for fun - choo choo). We've also got non-destructive ? methods that say does a named progress exist with the given date (requested/received/actioned) set. Also, got *very* badly burned when I discovered that find_or_create quietly ignores :conditions clauses but, of course, all my rspec stuff was passing. I do use it for really simple things. F --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "NWRUG" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nwrug-members?hl=en -~----------~----~----~----~------~----~------~--~---
