0
這是我知道自己做錯事情的那些年,但我看起來很明顯是聾啞,盲目。我希望另一雙眼睛能夠打開我自己的眼睛。關聯或遏制錯誤
我有一個ZipCode
模型和一個Incentive
模型。有一個榮耀的連接表(榮耀,因爲它有自己的鑰匙)坐在中間。連接表具有id
,incentive_id
和zip
字段(遺留數據庫)。如我ZipCode
模型HABTM Incentive
:
public $hasAndBelongsToMany = array(
'Incentive' => array(
'with' => 'ZipCodeIncentive',
'foreignKey' => 'zip',
'associationForeignKey' => 'incentive_id',
),
);
我Incentive
模型HABTM ZipCode
如下:
public $hasAndBelongsToMany = array(
'ZipCode' => array(
'with' => 'ZipCodeIncentive',
'foreignKey' => 'incentive_id',
'associationForeignKey' => 'zip',
),
我有一個方法,ZipCode::incentives($zip)
是希望所有的獎勵相關拉到指定的郵政編碼:
$incentives = $this->Incentive->find(
'all',
array(
'contain' => array('ZipCode'),
'fields' => array('Incentive.id', 'Incentive.name', 'Incentive.it_name', 'Incentive.amount', 'Incentive.state', 'Incentive.entire_state', 'Incentive.excluded', 'Incentive.is_active'),
'conditions' => array(
'Incentive.excluded' => 0,
'Incentive.is_active' => 1,
'OR' => array(
'Incentive.state' => 'US', # nationwide incentives
array(
# Incentives that apply to the entire state the zip code belongs to
'Incentive.entire_state' => 1,
'Incentive.state' => $state,
),
'ZipCode.zip' => $zip # specific to the building's zip code
)
),
'order' => array('Incentive.amount DESC'),
)
);
我得到的麻煩是以下錯誤:
SQL Error: 1054: Unknown column 'ZipCode.zip' in 'where clause'
的ZipCode
模型的表是沒有得到參加了SQL,但我還沒有掌握爲什麼尚未。值得一提的是,Incentive
模型綁定到MySql視圖,而不是表格,通過$useTable
。在這種情況下,我沒有看到任何暗示它應該成爲問題的東西,但它是非標準的。
如果您發現我錯過了什麼,請致電911或至少放棄一個答案。
衛生署!我知道這將會是這樣的。不像我預計的那樣明顯,但我感謝你的幫助。這一直在一天中更好的時候吸菸。如果SO會讓我這樣做,我會標記你的答案兩次。 – 2011-03-24 01:10:03