开发者

Ruby ActiveRecord Maximum

I am working with a Rails app that I need to return the maximum value for a particular row but also need to return the rest of the row co开发者_高级运维ntents.

Code:

medias = Media.maximum(:id, :conditions => ['medias.image = true AND medias.subscriber_id  = 37'], :group => ['subscriber_id'])

This is only returning the id and subscriber_id, I need to return all of the rows not just those two.

Example: In my medias table a subscriber can upload multiple photos. I am trying to group by the subscriber id and get the last entry for all subscribers. So basically I need a find all by maximum.


medias = Media.maximum(:id, :conditions => ['medias.image = true AND medias.subscriber_id  = 37'], :group => ['subscriber_id'])
trythis = Media.find(medias)


Media.order("subscriber_id DESC").limit(1).where("image = true").where("subscriber_id = ?", 37)

I think you're wanting to find the max subscriber_id, but if not, just replace that with what you're ordering on

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜