Query from tables that have one column name in common


#1

Hi!
I have a situation where I need to get data from multiple tables and two
of them share one column name. In table “order_items” and “products”
there is column “cost_price”. Now when I do the following query I get my
item.cost_price to receive its value from the “product” table, but I
would like to have it read from “order_items” table. Is there a way to
limit the joins to take only some specific columns from the “product”
table? Or is there a way to prevent “products” table column “cost_price”
to override the data received from the other table? Exclude it from the
query some way?

order_items = OrderItem.between(100.years.ago,
100.years.from_now).find(:all, :joins => [ {:order => :user}, :product],
:conditions => filters_for_business_unit)

@items = order_items.map do |item|

total_cost_price = item.cost_price

-Mika