0

내가

class Invoice < ActiveRecord::Base 
... 
belongs_to :seller, :class_name => "Client", :foreign_key => "provider", :conditions => ['is_provider = ?', true] 
belongs_to :customer, :class_name => "Client", :foreign_key => "receiver", :conditions => ['is_receiver = ?', true] 

내가 색인을 시도하고 내 모델에서 여러 has_one 협회있어 그것은 :

indexes [seller(:tbClientCode), seller(:tbClientLabel), seller(:tbClientName), seller(:tbClientNIP), 
    seller(:tbClientRegon), seller(:tbClientZip), seller(:tbClientCity), seller(:tbClientStreet), 
    seller(:tbClientHouseNr), seller(:tbClientHomeNr], :sortable => true, :as => :seller_fields  
has [seller(:is_provider), seller(:is_receiver)], :sortable => true, :as => :seller_attributes  

indexes [customer(:tbClientCode), customer(:tbClientLabel), customer(:tbClientName), customer(:tbClientNIP), 
    customer(:tbClientRegon), customer(:tbClientZip), customer(:tbClientCity), customer(:tbClientStreet), 
    customer(:tbClientHouseNr), customer(:tbClientHomeNr], :sortable => true), :as => :customer_fields  
has [customer(:is_provider), customer(:is_receiver)], :sortable => true, :as => :customer_attributes 

... 그리고는 약간의 오류가

발생
ERROR: index 'invoice_core': sql_range_query: ERROR: column reference "is_receiver" is ambiguous 
LINE 1: ...tomers_invoices"."id" = "invoices"."receiver" AND is_receive... 

변경 구문을 고객 (: tbClientName)에서 customer.tbClientName은 해결책이 아닙니다.

어떤 도움을 크게

을 감상 할 수있다

답변

1

음, 첫째 : 나는 당신이 실제로 하나 개의 필드에 모든 열을 결합 할 단 하나 개의 속성을 생각하지 않아?

따라서 여러 개의 열을 전달할 수 있지만 명시 적 배열을 전달하면 이러한 열을 하나의 필드/속성으로 그룹화합니다. 따라서 :as 옵션도 제거하십시오. 동일한 이름을 가진 모든 열을 함께 표시하지 않으려면 생성 된 SQL 문이 이해가되지 않습니다.

둘째 : 특성은 매우 자연 스럽기 때문에 정렬 할 수 있으므로 :sortable => truehas 호출에 전달할 필요가 없습니다. 또한 : 모든 필드를 정렬 할 수 있어야합니까? 그처럼 정렬 할 수있는 필드 만 표시하는 것이 좋습니다.

마지막으로, 아마도 가장 중요한 것은 실제로 발생하는 오류는 두 연관에 대한 조건 해시 때문입니다. 같은 테이블에 두 번 가입하고 있지만 조건에 테이블 참조가 없습니다. 두 조건 설정을 다음과 같이 변경해보십시오.

:conditions => {:is_provider => true} 
:conditions => {:is_receiver => true} 
+0

고마워요! 당신의 솔루션은 완벽하게 작동합니다 :) – zachar