sql - Complex rails find ordering -


I am trying to find out which orders will be in the name of their home and then the customer's last name .

  Customer.Find (: All, Conditions => ['customers.id IN (?)', Intersection] ,: joins = & gt; History history on history. Customer_ID = Customers.Histories.house_id = houses.id ',: order = & gt; Homes. Name ASC, Customer.Last_N ASC ",: Select =>" Customers. *, History. Job-Title, Homes. Name " )  

My problem is that it will return every history related to each customer.

If I add and do history, Finnish_diet IS Null is selected I For every customer coming in the histories, every history will stop, but also to stop the customers in the crossroads, who do not have any history or are returning to the Finnish_Data set.

Actually I Every customer has to return to the intersection, in which the name of the present house is (if they have it) and then the order is given after the name of their house

Customers < / P>

P>

  id last_name 1 forex 2 doors 3 green  

History

  id finish_date house_id customer_id 1 NULL 1 1 2 NULL 2 2 3 11/03/10 2 1 4 22/04/09 1 2  

NULL = Current home

Home

  ID name 1 A2b  

Results

intersections = 1,2

text "itemprop =" text ">

I think you need to use external join.

For example, this should work:

  Customer.find (: all,: conditions => ['customers.id IN' (?) And history Finish_date is zero, intersection] ,: joins = & gt; enter history on the left-hand side history customers.id = customers.id Join houses at the left OUTER history. House_id = houses.id ', order = & gt; ; "Houses.name ASC, Customer.Last_Now ASC",: Select => "Customers. *, History. Job-Title, Houses.")  

A collaboration between history and history and the House So you : Include & gt; [: History = & gt; : Home] instead of : joins options.

The only other thing is that the customers who do not have a home will be shown first in the list because they are listed first, in order to try the order option in order to compare the non-zero values Can:

 : order = & gt; You can specify what 'isnull (houses.name), houses.name, customers.last_name'  


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -