0

我有以下 2 个 named_scopes:

  named_scope :scope1,  lambda { |pi_id|
    { :select => "DISTINCT REF_PRO.*",
      :joins => "INNER JOIN LNK_PRO ON  LNK_PRO.PR_PRO_FK = REF_PRO.RPR_ID 
                 INNER JOIN EMI_SUBMISSION on EMI_SUBMISSION.SUB_ID =  LNK_PRO.PR_SUBMISSION_FK
                 INNER JOIN EMI_PERSON on EMI_PERSON.PER_ID = EMI_SUBMISSION.SUB_PI_FK ",
      :conditions=>["EMI_PERSON.PER_ID = ? ", pi_id],
      :group => "REF_PRO.RPR_ID"

    }
  }


  named_scope :scope2, lambda { |pi_id|
    { :select => "REF_PRO.*",
      :joins => "INNER JOIN REF_USER ON REF_USER.USR_ID = REF_PRO.RPR_CREATED_BY 
                 INNER JOIN LNK_USER_PI on LNK_USER_PI.USP_USER_FK = REF_USER.USR_ID ",
      :conditions=>["LNK_USER_PI.USP_PI_ID = ? ", pi_id]
    }
  }

我需要加入他们的结果。

有没有办法合并两个结果集?如果不是,我如何修改一个 named_scope 以便它返回上述命名范围的组合结果?

非常感谢你的帮助

4

1 回答 1

0

你可以这样做:

Model.scope1+Model.scope2
于 2012-10-02T16:41:31.103 回答