duplicate records of a query

1

I am making a query to find all those products that are not related to a table called Stock where the "Path" field within the Stock table is different from the id that I am passing through the URL. I'm doing it in the following way:

@productos = Producto.joins('left outer join stock on productos.Clave=stock.Articulo')
                     .select('productos.*,stock.Articulo')
                     .where('stock.ruta != ? AND productos.Status = ?', params[:id], "A")

The problem with this query is that it is showing me the repeated products, depending on the quantity of stocks to which this product is associated, how can I solve it?

    
asked by LuisC 17.11.2016 в 23:59
source

1 answer

0

You could try calling the distinct method, something like this:

@productos = Producto.joins('left outer join stock on productos.Clave=stock.Articulo')
                 .select('productos.*,stock.Articulo')
                 .where('stock.ruta != ? AND productos.Status = ?', params[:id], "A")
                 .distinct
    
answered by 18.11.2016 / 13:32
source