私はエンティティと国との間にHABTM関係があります。次のfindは、私が欲しいデータを返しますが、私は、エンティティからわずかティッカーフィールドを返すに削るにそれをダウンしたい:cakephpでHABTM関係を持つfindのcontainsを使う
$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));
が、それはありませんでした効果。
私はこのような見つける呼び出す前に、エンティティモデルに含まれて呼び出してみました:1064を含んで
$this->Entity->contain('ticker');
$blap = $this->Entity->Country->find('first', array('conditions' => array('Country.id' => 78)));
をしかし、それは、次のエラーメッセージ
27を生成した:あなたはSQLでエラーが発生しています構文;正しい 構文が行1 0 28の近くに '含む'を使用するように、ご使用のMySQLサーバーバージョンに対応する マニュアルを確認してください。SELECT
Country
。id
,Country
。name
,Country
。hash
FRcountries
ASCountry
WHERECountry
。id
= 78LIMIT 1 1 1 1 29 SELECTEntity
。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
。私は結果を取捨選択するためのコードを書くことができ、バックアップ計画としてEntity
ASentities
FROMdefault_country
(CountriesEntity
。country_id
= 78 ANDCountriesEntity
。entity_id
=Entity
。id
) ONCountriesEntity
AScountries_entities
をJOIN 32 32 1
$ blapで私が望む値を引き出すことができましたが、findコマンド自体の中でフィルタリングする方法があると思いました。