Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:12:04+00:00 2026-06-14T00:12:04+00:00

I have models set up similar to this: class Book < ActiveRecord::Base has_many :histories,

  • 0

I have models set up similar to this:

class Book < ActiveRecord::Base
  has_many :histories, as: :object
end

class Magazine < ActiveRecord::Base
  has_many :histories, as: :object
end

class Action < ActiveRecord::Base
  belongs_to :object, polymorphic: true

  default_scope order(:done_at)

  # a history contains an action and the time that action 
  # occurred on the object it belongs to
end

Now, I want to get a list of the 5 lastest actions that have occurred on all objects. So I can do something like:

Action.limit(5)

However, the problem is that if two actions have recently occurred on the same book, both actions will be retrieved. I want to only retrieve the lastest one. How do I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:12:05+00:00Added an answer on June 14, 2026 at 12:12 am

    Figured out that what I wanted was the group option. So I can do something like:

    Action.group(:object_id).group(:object_type).limit(5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two models set up like this: class User < ActiveRecord::Base #
I have the following models set up: class Contact < ActiveRecord::Base belongs_to :band belongs_to
Suppose I have my models set up already. class books(models.Model): title = models.CharField... ISBN
I have a model set out like so: class Rating # user_id, author_id end
I have a code similar to this: My View @model MyCode.Models.RemarksModel foreach (var row
With a simple model like that class Model < ActiveRecord::Base # ... end we
I have a parent class in rails that inherits from ActiveRecord::Base. I'm trying to
I have something similar to this model: public class Product { public int ID
I have a model similar to this: public class SampleModel { public Product Product
I have set up a few models in a simple django project. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.