I want to compare tables with Ruby on Rails

Asked 2 years ago, Updated 2 years ago, 84 views

If the specified columns in the rails tables overlap, I would like to create a new table or array without duplicate records.
For example, if you want to see duplicate names, use the following two tables. Enter a description of the image here

I would like to do the following.
Enter a description of the image here

I can't get an image of the code, so could someone please let me know?

ruby-on-rails ruby

2022-09-30 21:44

1 Answers

I don't think there's a very good way.

Model1.all.to_a+Model2.where.not(name:Model1.all.select(:name)) to_a

I think it's better than doing it.


2022-09-30 21:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.