Mika Mustalahti
2009-Apr-16 13:06 UTC
Query from tables that have one column name in common
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---