Hi, > But... what I need to do is something like: > > User.all(:order => [:denormalized_posting_stats.desc]).each do |user| > current = user.postings.last > previous = user.postings.reverse[1] > delta_posting_stats = current.posting_stats - previous.posting_stats > report_on current, previous, delta_ posting_stats # fictitious > reporting method > end > > So this is ok, but maybe not wonderful but it seems suspiciously like > it deserves a finder method. But I can't figure out how to concoct > one. > > Any ideas?
As of right now I don't think there's a super clean way to retrieve the last and second to last rows from an association in sam/dm-core. However, that was mostly due to an oversight I've corrected in dkubb/ dm-core. (well, actually the behavior emerged after I rearranged the code and made the one to many collection inherit from collection) You'll be able to use last(2) like this once dkubb/dm-core becomes more stable: User.all(:order => [:denormalized_posting_stats.desc]).each do |user| previous, current = user.postings.last(2) delta_posting_stats = current.posting_stats - previous.posting_stats report_on current, previous, delta_ posting_stats end 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 -~----------~----~----~----~------~----~------~--~---
