Dan--

On Dec 21, 2008, at 10:45 AM, Dan Kubb (dkubb) wrote:

> 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

Thanks for the reply. As of right now, I've settled on the (kinda ugly):

first_and_last = @user.posting_stats(:limit => 2, :order => [:id.desc])

This implies understanding the implementation detail of reverse  
ordering the result array, but your syntax seems better because last()  
should work just like it does on an ordered Ruby collection.

Thanks again... I'll look forward to that making its way into stable  
core.

--s


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to