ruby on rails - How do I get ActiveRecord to use data from joins? -


i'm running activerecord statement

@items = item.joins(:order => :person)              .select('items.*').select('orders.*')              .includes(:order => [:person, :organization])              .order('created_at desc')              .limit(10) 

and these queries:

select items.*, orders.* items inner join orders on orders.id = items.order_id inner join people on  people.id = orders.person_id items.deleted_at null order created_at desc limit 10 item load (0.001ms)   select (trace) select orders.* orders orders.deleted_at null , orders.id in (51, 50, 49, 48, 47, 46) order orders.created_at desc order load (0.000ms)   select (trace) select people.* people people.deleted_at null , people.id in (11, 22, 21, 19, 18) person load (0.000ms)    select (trace) select organizations.* organizations organizations.id in (1) organization load (0.000ms)   

why activerecord re-selecting data database if select'd using inner join in first select items.*, orders.* query? how can hydrate item.order without going db?

hi when using activerecord joins finding matching data between relational model.

example: if person has many items , items belongs person activerecord query be:

item.find(:all, :joins => :person, :select => "items.name, persons.full_name", :conditions => ["persons.full_name = ?", 'allen', :order => "persons.created_at desc"]) 

the above code returns item name , person's full name full name = 'allen' , orders created_at desc or persons table. there many inner join queries in logs when person's id equals item's person_id column.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -