On Feb 23, 4:17 pm, Phrogz <[email protected]> wrote: > On Feb 23, 4:56 pm, Phrogz <[email protected]> wrote: > > > def vote_total > > votes.inject(0){ |sum,vote| sum + vote.count } > > end > > When writing up a pared down test case doesn't give the answer, > hitting send on a global email most often will. :) > > I discovered that changing the above to > votes_dataset.all.inject... > prevents it from returning an array of cached records.
You could use votes(true) as well. > This leaves me with two questions: > 1) Why is votes() returning the cached set, and Associations are cached, association datasets are not. You can tell it not to cache by calling the association with the true argument, or by clearing the cache manually. Refreshing an object clears the cache. Objects are refreshed when created, but not when updated. > 2) Of course my technique of discovering changed composite values > can't possibly work in a before_save hook alone. My best thoughts now > are adding a custom pre_modify call that caches all 'interesting' > values for the before_save to compare against. If someone else has run > into this need before, how have you solved it? I'm not sure exactly what you want to do, but the best solution might involve a database trigger. If you don't want to do that, you can use after_initialize to copy the values initially used, and then check against that in before_save. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" 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/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
