0

そのため、上記に少し行き詰まっており、SQLサーバーエラーが発生し続けています。はい、mssql サーバーを使用しています :| - 私のデータベースではありません。

少し背景を説明すると、関係する私の関係は次のようになります。

AssetMaintenanceRecord->(所属)->Asset->(所属)->Project->(ある)->ProjectManager

(ProjectManager は、人事テーブルの別名モデルのようなものです。プロジェクト テーブルには、ProjectManager の ID があり、これは単なる人事 ID です。

そこで、ProjectManager で検索してすべての AssetMaintenanceRecords を選択する単純なフィルターを実行しようとしています。

関連する AssetMaintenanceRecordsController.php のインデックス関数は次のようになります。

public function index() {
        $conditions = NULL;
        if (isset($this->params['url']['report']) && $this->params['url']['report']  == 'open') {
            $conditions[] = array('CompletedDate' => NULL);
        }

        if (isset($this->params['url']['report']) && $this->params['url']['report'] == 'notified') {
            $conditions[] = array('NotifiedDate BETWEEN ? AND ?' => array(date('M d Y g:iA', strtotime($this->params['url']['datefrom'])), date('M d Y g:iA', strtotime($this->params['url']['dateto']))));
        }

        if (isset($this->params['url']['report']) && $this->params['url']['report'] == 'completed') {
            $conditions[] = array('CompletedDate BETWEEN ? AND ?' => array(date('M d Y g:iA', strtotime($this->params['url']['datefrom'])), date('M d Y g:iA', strtotime($this->params['url']['dateto']))));
        }

        if (isset($this->params['url']['project'])) {
            $conditions[] = array('Asset.aCurrProject' => $this->params['url']['project']);
        }

        if (isset($this->params['url']['ptCode']) && $this->params['url']['ptCode'] != NULL) {
            $conditions[] = array('Asset.ptCode' => $this->params['url']['ptCode']);
        }

        if (isset($this->params['url']['asset']) && $this->params['url']['asset'] != NULL) {
            $conditions[] = array('Asset.aFullCode' => $this->params['url']['asset']);
        }

        if (isset($this->params['url']['pm']) && $this->params['url']['pm'] != NULL) {
            $pm_search_terms = explode(' ', $this->params['url']['pm']);
            foreach($pm_search_terms as $pm_search_term) {
                $conditions[] = array(
                                'OR' => array(
                                        'ProjectManager.PerGivenName LIKE' =>'%'.$pm_search_term.'%',
                                        'ProjectManager.PerSurname LIKE' =>'%'.$pm_search_term.'%',
                                  )
                          );
            }
        }

        $this->paginate['AssetMaintenanceRecord'] = array(
            'contain' => array(
              'Asset' => array(
                'Project' => array(
                    'ProjectManager'
             ))
            ),
          'order' => 'CompletedDate ASC',
          'limit' => 10
        );

        $planttype = $this->AssetMaintenanceRecord->Asset->PlantType->find('list');
        $this->set(compact('planttype'));
        $this->AssetMaintenanceRecord->recursive = -1;
        $this->set('records', $this->paginate('AssetMaintenanceRecord', $conditions));
    }

ProjectManager フィルターがなくても問題なく動作し、ProjectManager 配列などをエコーアウトできますが、検索用語を入力すると、次のエラーが発生します。

マルチパート識別子 "ProjectManager.PerSurname" をバインドできませんでした。

実行された sql は次のようになります。

'SELECT TOP 10 [AssetMaintenanceRecord].[MtceRegID] AS [AssetMaintenanceRecord_ 0], [AssetMaintenanceRecord].[AssetID] AS [AssetMaintenanceRecord _1], CAST(CAST([AssetMaintenanceRecord].[MtceRegNote] AS VARCHAR(8000)) AS TEXT) AS [AssetMaintenanceRecord_ 2], [AssetMaintenanceRecord].[POno] AS [AssetMaintenanceRecord _3], CAST(CAST([AssetMaintenanceRecord].[NotifiedDate] AS VARCHAR(8000)) AS TEXT) AS [AssetMaintenanceRecord_ 4], CAST(CAST([ AssetMaintenanceRecord].[CompletedDate] AS VARCHAR(8000)) AS TEXT) AS [AssetMaintenanceRecord _5]、[AssetMaintenanceRecord].[MtceRegTitle] AS [AssetMaintenanceRecord_ 6]、CAST(CAST([AssetMaintenanceRecord].[CreatedDate] AS VARCHAR(8000) ) AS TEXT) AS [AssetMaintenanceRecord]_7]、[AssetMaintenanceRecord].[CreatedUserID] AS [AssetMaintenanceRecord_ 8]、CAST(CAST([AssetMaintenanceRecord].[ModifiedDate] AS VARCHAR(8000)) AS TEXT) AS [AssetMaintenanceRecord _9]、[AssetMaintenanceRecord].[ModifiedUserID] AS [AssetMaintenanceRecord_10 ]、[Asset].[aID] AS [ Asset_11]、[Asset].[ptCode] AS [Asset_12 ]、[Asset].[aNo] AS [ Asset_13]、[Asset].[aFullCode ] AS [Asset_ 14], [Asset].[aDesc] AS [Asset _15], [Asset].[aMake] AS [Asset_ 16], [Asset].[aModel] AS [Asset _17], [Asset]. [aSerialNo] AS [Asset_ 18]、[Asset].[aRegNo] AS [Asset _19]、CAST(CAST([Asset].[aRegExpDate] AS VARCHAR(8000)) AS TEXT) AS [Asset_ 20]、[Asset ].[aActive] AS [アセット_21]、[Asset].[aIncAssetRpt] AS [Asset_ 22]、[Asset].[aIncFinanceRpt] AS [Asset _23]、[Asset].[aIsTrailer] AS [Asset_ 24]、[Asset].[aIsSurveyEquip] AS [ Asset_25]、[Asset].[aCostedItem] AS [Asset_26 ]、[Asset].[aCostedPeriod] AS [ Asset_27]、[Asset].[aWarrantyPeriod] AS [Asset_28 ]、[Asset].[aPONo ] AS [Asset _29], CAST(CAST([Asset].[aPODate] AS VARCHAR(8000)) AS TEXT) AS [Asset_ 30], CAST(CAST([Asset].[aPOCostExGst] AS VARCHAR(8000)) AS TEXT) AS [Asset _31], [Asset].[aQtyStock] AS [Asset_ 32], [Asset].[aQtyInUse] AS [Asset _33], [Asset].[aCurrProject] AS [Asset_ 34], [Asset ].[aCurrOperator] AS [資産_35]、[資産].[盗まれた] AS [資産_36]、CAST(CAST([Asset].[aStolenDate] AS VARCHAR(8000)) AS TEXT) AS [Asset _37]、[Asset].[aWO] AS [Asset_ 38]、CAST(CAST([Asset]. [aWODate] AS VARCHAR(8000)) AS TEXT) AS [Asset _39], [Asset].[aSold] AS [Asset_ 40], CAST(CAST([Asset].[aSoldDate] AS VARCHAR(8000)) AS TEXT ) AS [Asset _41], CAST(CAST([Asset].[aSoldPrice] AS VARCHAR(8000)) AS TEXT) AS [Asset_ 42], CAST(CAST([Asset].[aNotes] AS VARCHAR(8000)) AS TEXT) AS [Asset _43]、CAST(CAST([Asset].[LastModDate] AS VARCHAR(8000)) AS TEXT) AS [Asset_ 44]、CAST(CAST([Asset].[CreatedDate] AS VARCHAR(8000) )) AS TEXT) AS [Asset _45], [Asset].[aCat] AS [Asset_ 46], [Asset].[aPoliceRptNo] AS [Asset _47], [Asset].[aRelatedAssetID] AS [Asset_48]、[Asset].[aRelatedAssetFullCode] AS [Asset _49]、[Asset].[aPayMethod] AS [Asset_ 50]、[Asset].[aInvoiceNo] AS [Asset _51]、CAST(CAST([Asset]. [aLastFuelDate] AS VARCHAR(8000)) AS TEXT) AS [Asset_ 52], [Asset].[aFuelType] AS [Asset _53] FROM [tbMtceRegister] AS [AssetMaintenanceRecord] LEFT JOIN [tbAsset] AS [Asset] ON ([ AssetMaintenanceRecord].[AssetID] = [Asset].[aID]) WHERE [CompletedDate] IS NULL AND [Asset].[aCurrProject] IS NULL AND (([ProjectManager].[PerGivenName] LIKE '%test%') OR ( [ProjectManager].[PerSurname] LIKE '%test%')) ORDER BY [CompletedDate] ASC'

私には問題ないように見えますが、明らかにどこかで間違っていますか?

どんな助けでも感謝します。

前もって感謝します。

4

1 に答える 1

0

ProjectManager はFROMまたはに含まれていませんJOINが、 で使用されていWHEREます: OR ([ProjectManager].[PerSurname] LIKE

于 2012-11-20T22:43:17.820 に答える