Hi Jacques, > Hi. I really need some counter caches in some of my models (to keep > track of a few "has n" relations) and I haven't been able to find any > standard or plugin solutions. Is there one available, or does everyone > using datamapper currently do it themselves with callbacks?
afaik, there's no plugin to do this but it would be relatively simple to assemble one using existing plugins. > Also, let me know if you guys consider counter caches bad practice or > something. When you add a counter cache you're denormalizing the data, which I would not consider unless there was an actual need, proven through benchmarking before and after adding the cache. IMHO denormalizing without first proving you need to do so is a code smell. However, I know there are legitimate cases where it can boost performance but you need to test first. > Seems strange that its not built in. Everything in DataMapper is based on real need, and features are only added to dm-core if they need to be in core, otherwise it should be a plugin. In this case it would be easy to assemble a counter cache using hooks and dm-adjust, as already mentioned in this thread. I can only assume that the only reason it hasn't been packaged into a plugin yet is that it's either not common enough, or assembling it using available primitives is simple enough that it's not caused anyone enough pain. Dan (dkubb) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" 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/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
