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

  • Home
  • SEARCH
  • 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 9096481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:51:50+00:00 2026-06-16T23:51:50+00:00

I recently stumbled upon this blog post, which states that Array#uniq behaves differently on

  • 0

I recently stumbled upon this blog post, which states that Array#uniq behaves differently on arrays of ActiveRecord objects, but neither gives a specific example for it, nor does it tell the reason for this.

I would like to see a reproducible example of this the different behavior and an explanation for it.

edit:
I’m talking about Array#uniq, not ActiveRecord::Relation#uniq. If the latter one is what the above mentioned blog post actually means, then my question has been already been answered by loz (see below).

  • 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-16T23:51:51+00:00Added an answer on June 16, 2026 at 11:51 pm

    Active record ‘arrays’ are not arrays they are a different. So (asside from .all, which explicitly returns an array) if you use associations or similar you get different behavior, as lazy loading is in operation:

    post = Post.find(1)
    post.comments
    => Array[Comment(:1), Comment(:2)]... etc
    

    Looks like an array, but

    post.comments.class
    => ActiveRecord::Relation
    

    So performing Uniq operates on the relationship, which adds more constraints to the query which will eventually be run on the database when the records are required:

    post.comments.uniq
    

    This will perform the uniq by doing a DISTINCT or UNIQUE query clause in SQL, rather than doing uniq in ruby..

    Uniq details are found here: rails uniq documentation, and you can see about what returns ActiveRecord::Relation in active record here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on topcoder recently and I stumbled upon this question which I
Stumbled upon this interview question recently, Given a 2-dimensional array of characters and a
I recently stumbled over this post , which introduces the collect method for Scala
I recently stumbled upon this interesting concept that may save me much testing efforts.
Recently stumbled upon this post whilst trying to decide on the best way of
Recently stumbled upon a stock video footage site http://www.pond5.com/stock-video-footage/1/*.html , and saw that they
I recently stumbled upon a global hotkey class ( This one ), it works
A problem that I stumbled upon recently, and, even though I solved it, I
I recently stumbled upon this page . And I was particularly interested about the
I recently stumbled upon a problem where I have a view that can be

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.