2011-10-21 31 views
3

我使用rails 2.3.5,will_paginate-2.3.15和postgress。 我有2個belongs_to到同一張表。 如果我首先搜索屬性,然後搜索別名表屬性,則會引發異常。如果我扭轉它的工作條件的順序...將在分頁關聯時分頁丟失FROM子句條目

class House 
    belongs_to :owner, :class => "User" 
    belogns_to :creator, :class => "User" 
end 

House.paginate(
    :page=>1, 
    :include=>[:creator, :owner], 
    :per_page=>20, 
    :conditions=>"houses.city ILIKE E'%new yo%' and owners_houses.architect ILIKE E'%tom%'") 

提高

ActiveRecord::StatementInvalid: PGError: ERROR: missing FROM-clause entry for table "owners_houses", 

日誌中沒有FROM子句

加入在

這工作:

House.paginate(
    :page=>1, 
    :include=>[:creator, :owner], 
    :per_page=>20, 
    :conditions=>"owners_houses.architect ILIKE E'%tom%' and houses.city ILIKE E'%new yo%'") 

是這是will_paginate中的一個錯誤?這是爲什麼發生?

回答

0

檢查爲WORKING和NON WORKING語句生成的Sql查詢的development.log