mardi 14 novembre 2017

How to get unique/distinct values in included in render json

I'd like the instituciones values to be unique/distinct when rendering profesionales.
The model is as shown:

class Profesional < ApplicationRecord
has_many :instituciones, through: :horarios

and profesionales_controller.rb goes:

render json: @profesionales.to_json(include: {
instituciones: { only: [:id] }
})

But I get some instituciones repeated. Is there a way to apply uniq or distinct?

Aucun commentaire:

Enregistrer un commentaire