I'm making a query to find all those products that are not related to a table called Stock
where the field Ruta
within the table Stock
is different from id
I'm going through the url, that means searching for all those products that are not associated with Stock
, where the path of said Stock
equals the parameter of the url.
I'm doing it this 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")
I have a small problem and I am looking for those records that are not associated with Stock
where the field Ruta
is different from the id
I am passing as a parameter.
When the product is not associated with Stock
and I create a Stock
associated with the product, it does not bring the query, and it is just what I want, but if the product is already associated with another Stock
, so I have it associated to the Stock
with the Ruta
id of the parameter, it keeps bringing it because another Stock
with another Ruta
id has it.
How could I solve it?
The structure of the tables are: a "Product" has many "Stock" and a "Stock" belongs to a "Product"
Product: Password, Product, Status
Stock: IdStock, Article, Route