2012-02-21 4 views
0

私はエンティティと国との間に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 Countryid, Countryname,Countryhash FR countries AS Country WHERE Countryid = 78LIMIT 1 1 1 1 29 SELECT Entityid, Entityticker,Entityshares_outstanding, Entitybegin_fiscal_calendar,Entitylast_reported_quarter, Entitynext_report_date,Entityobsolete_groups, Entityactual_fiscal_year_end,Entityfull_name, Entitydepricated,Entityobsolete_country_id, Entityticker2,Entityhash,CountriesEntityid, CountriesEntitycountry_id,CountriesEntityentity_id, CountriesEntity。私は結果を取捨選択するためのコードを書くことができ、バックアップ計画としてEntity AS entities FROM default_countryCountriesEntitycountry_id = 78 AND CountriesEntityentity_id = Entityid) ON CountriesEntity AS countries_entitiesをJOIN 32 32 1

$ blapで私が望む値を引き出すことができましたが、findコマンド自体の中でフィルタリングする方法があると思いました。

答えて

0

Countryモデルで検索を呼び出す場合は、次のように含める必要があります。$this->Entity->Country->contain()

また、コールを直接コールに含めることはできません。 $this->Entity->Country->contain(array('fields' => 'ticker'))のように電話してみてください。

関連する問題