I have three tables,
products has 3 columns, let them be product_id,retailer_id,id
product_urls has 2 columns, url_id,id
urls has 2 columns, url_id, absolute_url
All the associations has been done in models.
Products & product_urls are joined on id = id (Products "has many" relationship with product_urls)
product_urls & urls are joined on Url_id = id (product_urls "belongs to" relationship with urls)
products & urls have "has many relationship"
I am trying to write a query, which selects A,B,C column from Table1 and X from Table3.
My query is:
- Product.joins(:urls).select(:product_id,:retailer_id,:absolute_url).where(:id=>100, :urls => {:url_id=>100})
I am able to execute the query without any error, but I am not able to get data for X. when I check for sql query it is
- select products.product_id, products.retailer_id, products.absolute_url ........ is executed.
Please help me how to fetch value from urls??
Table1.joins(:table3).select("A,B,C,table3.X").where(:D=>100, :table3 => {:Y=>100})Product.joins(:urls).select("products.product_id,products.retailer_id,urls.absolute_url").where(:id=>100, :urls => {:url_id=>100})