2014-01-10 84 views
1
未知列

我有以下的數組,我想保存到數據庫..CakePHP的:與saveMany

$this->ProgramApplication->saveMany($priApps); 

$priApps: 
Array 
(
    [0] => Array 
     (
      [ProgramCurrentResidence] => Array 
       (
        [program_id] => 3698076220130520 
        [customer_id] => jraer4081 
        [residence_duration] => 61-90-days 
        [residence_stability] => renting-leasing 
        [payment_current] => yes 
        [payment_amount_past_due] => 
        [landlord_name] => Blake Woods 
        [landlord_phone] => (269)777-7777 
        [landlord_fax] => 
        [notes] => 
       ) 


      [ProgramPreviousResidence] => Array 
       (
        [program_id] => 3698076220130520 
        [customer_id] => jrayner4081 
        [residence_duration] => 1year 
        [street_address] => 1637 Colfax Ave 
        [city] => The Harbor 
        [state] => me 
        [zip] => 49022 
       ) 
      ) 

    ) 

那不斷拋出下面的錯誤...

數據庫錯誤 錯誤:SQLSTATE [42S22]:未找到列:1054未知列'where子句中'ProgramCurrentResidence.program_id'

SQL查詢:SELECT ProgramApplicationprogram_idProgramApplicationcustomer_idProgramApplicationsecondary_customer_idProgramApplicationsecondary_customer_relationshipProgramApplicationsales_associateProgramApplicationstoreProgramApplicationcreated_onProgramApplicationdate_submittedProgramApplicationdate_deliveredProgramApplicationstock_numberProgramApplicationdeal_statusProgramApplicationdeal_status_conditional_reasoningProgramApplicationtransfered_to_dealpackProgramApplicationpresubmittal_notesProgramApplicationunderwriters_notesProgramApplicationmodified_byexpreta2_x12programs AS ProgramApplication WHERE((ProgramCurrentResidenceprogram_id = '3698076220130520')和(ProgramCurrentResidencecustomer_id = 'jrayner4081'))LIMIT 1

這裏是我的ProgramCurrentResidence模型...

<?php 
class ProgramCurrentResidence extends AppModel { 

    public $useTable = 'program_current_residences'; 

    public $primaryKey = 'program_id'; 

    public $belongsTo = array(
     'ProgramApplication' => array(
      'foreignKey' => 'program_id' 
      ) 
     ); 

} 
?> 

有點碼從程序應用模型

<?php 

class ProgramApplication extends AppModel { 

    public $useTable = 'programs'; 
    public $primaryKey = 'program_id'; 

    public $actAs = array('Containable'); 

    public $belongsTo = array(
     'Inventory' => array(
      'foreignKey' => 'stock_number' 
     ), 
     'Customer' => array(
      'foreignKey' => 'customer_id' 
     ), 
     'Employee' => array(
      'foreignKey' => 'sales_associate' 
     ), 
     'CustomerPersonalInformation' => array(
      'foreignKey' => 'customer_id' 
     ), 
     'CustomerContactInformation' => array(
      'foreignKey' => 'customer_id' 
     ), 
     'CustomerMarketingOption' => array(
      'foreignKey' => 'customer_id' 
     ) 
    ); 


    public $hasOne = array(
     'Desklog' => array(
      'foreignKey' => 'program_id' 
     ), 
     'Funding' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramCurrentResidence' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramPreviousResidence' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramCurrentEmployment' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramPreviousEmployment' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramIncome' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramReference' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramAdditionalInformation' => array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramDoublePreviousEmployment'=> array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramDoublePreviousResidence'=> array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramExpense'=> array(
      'foreignKey' => 'program_id' 
     ), 
     'ProgramVerificationWorksheet'=> array(
      'foreignKey' => 'program_id' 
     ) 
    ); 

} 

?> 

這可能是包含你談論..

// Get all the data corrosponding to the secondary customer 
       $secondaryRow = $this->Customer->find('all', array(
        'conditions' => array("Customer.customer_id" => $secondary), 
        'contain' => array(
         'CustomerPersonalInformation', 
         'CustomerContactInformation', 
         'CustomerMarketingOption', 
         'ProgramApplication' => array(
          'ProgramCurrentResidence', 
          'ProgramPreviousResidence', 
          'ProgramCurrentEmployment', 
          'ProgramPreviousEmployment', 
          'ProgramIncome', 
          'ProgramAdditionalInformation', 
          'ProgramDoublePreviousEmployment', 
          'ProgramDoublePreviousResidence', 
          'ProgramExpense', 
          'ProgramVerificationWorksheet' 
         ), 
         'CustomerInteraction' 
        ), 
       )); 

我知道表中包含使用的每個字段,但由於某些原因,它會繼續吐出此錯誤?我假設它的模型,但我可能是錯的。

+0

看起來好像從expreta2_x12表中選擇的數據未加入ProgramCurrentResidence –

+0

expreta2_x12是數據庫。 – Subie

回答

1

看起來好像你在ProgramApplication上找到了一個程序,ProgramApplication的模型與ProgramCurrentResidence沒有任何關係。 您可能需要將hasOne或hasMany的ProgramCurrentResidence添加到ProgramApplication模型。

+1

從程序應用程序模型中添加了代碼。它看起來是否正確或我需要添加hasMany? – Subie

+1

@Subie你可以發佈你的整個ProgramApplication模型嗎?因爲從你展示的內容看來,這似乎應該起作用,問題可能是其他一些查詢......你在上面的某個地方找到「包含」了嗎? –

+1

我們有一個包含。我已經在上面發佈了。 – Subie