I'm having an issue where I just need to remove the duplicates from 2 array of active record objects. The only thing is it is removing it from the database only and I just need it removed from the array in this case. I followed this Remove object from an array of objects and also tried a few other things and they were able to remove it from memory and explicitly remove it from array and not the database but I'm not able to replicate it. Any suggestions would be great. Thanks all!
company_links = CompanyLinkType.where(company_id: company_ids, contact_linktype_id: 3)
other_company_links = CompanyLink.where(company_id: company_ids, link_type: 'Twitter')
company_links.each do |company_link|
other_company_links.each do |other_company_link|
# checks if id and url match, need to remove obj from company_link array
if other_company_link.company_id == company_link.company_id && other_company_link.url == company_link.contact_link_url
company_link.delete
Rails.logger.info"+++++++++DELETED++++++++++"
end
end
end
company_links || other_company_linksit will return same result as you require.