Forum: Ruby on Rails Query from tables that have one column name in common

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mika M. (Guest)
on 2009-04-16 17:06
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
This topic is locked and can not be replied to.