Answer the question
In order to leave comments, you need to log in
How to prevent duplicate entries?
Let's say I have several hundred records in the database in one of the tables. And some of these records have the same name (name). So here's how to prevent so that records with the same name are not output in JSON. That is, suppose that there are 6 identifiers named "Manager" and of these six, only 1 should be displayed in json (which one does not matter). And also in json an element with the total number of entries is displayed, you need to make sure that the total number is also displayed but without duplicate entries.
class WorksController < ApplicationController
def index
works = paginate Work.all.order(:name), per_page: 10
render json: { data: works.as_json, meta: { total: Work.count } }
end
end
Answer the question
In order to leave comments, you need to log in
You have a clear problem with the database architecture, this problem needs to be solved in this direction.
What you are trying to do is a bicycle, and already rusty through and through, before it even left the assembly line.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question