我在實體和國家之間有HABTM關係。下面發現返回我想要的數據,但我想以削減下來,從實體只返回股票領域:在cakephp中使用包含與HABTM關係的查找
$blap = $this->Entity->Country->find('first', array('conditions' => array('Country.id' => 78)));
所以我增加了一個包含這樣的:
$blap = $this->Entity->Country->find('first', array('conditions' => array('Country.id' => 78),'contain'=>'Entity.ticker));
但沒有影響。
我打過電話呼叫找到這樣之前包含在實體模型:
$this->Entity->contain('ticker');
$blap = $this->Entity->Country->find('first', array('conditions' => array('Country.id' => 78)));
但是產生以下錯誤消息
27包含1064:你在你的SQL有一個錯誤句法;請檢查 手冊,該手冊對應於您的MySQL服務器版本右邊的 語法,以在第1行的'contains'附近使用。0 28 SELECT
Country
。id
,Country
。name
,Country
。hash
FROMcountries
ASCountry
WHERECountry
。id
= 78限制1 1 1 1 29選擇Entity
。id
,Entity
。ticker
,Entity
。shares_outstanding
,Entity
。begin_fiscal_calendar
,Entity
。last_reported_quarter
,Entity
。next_report_date
,Entity
。obsolete_groups
,Entity
。actual_fiscal_year_end
,Entity
。full_name
,Entity
。depricated
,Entity
。obsolete_country_id
,Entity
。ticker2
,Entity
。hash
,CountriesEntity
。id
,CountriesEntity
。country_id
,CountriesEntity
。entity_id
,CountriesEntity
。default_country
FROMentities
ASEntity
JOINcountries_entities
ASCountriesEntity
ON (CountriesEntity
。country_id
= 78和CountriesEntity
。entity_id
=Entity
。id
)32 32 1
作爲備份計劃我可以編寫代碼通過的結果進行篩選在$ blap中,並提取出我想要的值,但我認爲有一些方法可以在find命令本身內進行過濾。