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 6852397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:21:56+00:00 2026-05-27T01:21:56+00:00

I have an nested array and want to remove the entries that matches the

  • 0

I have an nested array and want to remove the entries that matches the info on my model.

My array looks roughly like this:

[{"id"=>"72157627540544488", "primary"=>"6090588224", "photos"=>"49", "videos"=>0, "title"=>"Title1", "description"=>""},
{"id"=>"72157627309708150", "primary"=>"5987891163", "photos"=>"49", "videos"=>0, "title"=>"Title2", "description"=>""},
{"id"=>"72157626646787712", "primary"=>"5687687064", "photos"=>"11", "videos"=>0, "title"=>"Title3", "description"=>""},
{"id"=>"72157626646672290", "primary"=>"5687629990", "photos"=>"33", "videos"=>0, "title"=>"Title4", "description"=>""}] 

And my model:

id               :integer         not null, primary key
name             :string(255)
set_id           :integer
thumb_url        :string(255)
created_at       :datetime
updated_at       :datetime

What I’m trying to accomplish is to remove from the array all the elements where the value of id is duplicated in any of the set_id in my model.

  • 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-05-27T01:21:57+00:00Added an answer on May 27, 2026 at 1:21 am

    You can do something like:

    array.reject{|element| Model.exists?(:set_id => element['id'])}
    

    where array is the array and Model is the model class. This will return a new array with the elements with duplicate id’s removed.

    Array.reject returns a copy of the array without the elements where the block passed in returns true.

    ActiveRecord.exists? returns true if a model exists in the database with the given conditions.

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

Sidebar

Related Questions

I have a hierarchically nested associative array. It looks like this: A = {
I have a 2D array that looks like this: array(2) { [45]=> array(5) {
I have a array with nested dictionary data like this: [{ link : [
I have a typical nested tree model and I want to build an array
I have a binary, the database table of relationships looks like this: +----+----------+---------+-----+ |
I have an array of arrays that I want to pass into a DLL.
I have this array I want to get the Values ABC ,1,2 and so
I have a messy tree multidimensional array that I want to do the following
I have a generated nested Array which I store some data. How can i
How have you explained nested arrays to a programmer. I'm thinking someone that has

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.