我有以下的數組,我想保存到數據庫..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 ProgramApplication
。 program_id
,ProgramApplication
。 customer_id
,ProgramApplication
。 secondary_customer_id
,ProgramApplication
。 secondary_customer_relationship
,ProgramApplication
。 sales_associate
,ProgramApplication
。 store
,ProgramApplication
。 created_on
,ProgramApplication
。 date_submitted
,ProgramApplication
。 date_delivered
,ProgramApplication
。 stock_number
,ProgramApplication
。 deal_status
,ProgramApplication
。 deal_status_conditional_reasoning
,ProgramApplication
。 transfered_to_dealpack
,ProgramApplication
。 presubmittal_notes
,ProgramApplication
。 underwriters_notes
,ProgramApplication
。 modified_by
從expreta2_x12
。 programs
AS ProgramApplication
WHERE((ProgramCurrentResidence
。program_id
= '3698076220130520')和(ProgramCurrentResidence
。customer_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'
),
));
我知道表中包含使用的每個字段,但由於某些原因,它會繼續吐出此錯誤?我假設它的模型,但我可能是錯的。
看起來好像從expreta2_x12表中選擇的數據未加入ProgramCurrentResidence –
expreta2_x12是數據庫。 – Subie