【发布时间】:2012-02-21 14:31:08
【问题描述】:
我在实体和国家之间有 HABTM 关系。以下查找返回我想要的数据,但我想将其缩减为仅从实体返回ticker 字段:
$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));
但这没有任何效果。
在调用 find 之前,我尝试在实体模型上调用 contains:
$this->Entity->contain('ticker');
$blap = $this->Entity->Country->find('first', array('conditions' => array('Country.id' => 78)));
但这会产生以下错误消息
27 包含 1064:您的 SQL 语法有错误;检查 与您的 MySQL 服务器版本相对应的手册 在第 1 行的“包含”附近使用的语法 0 28 SELECT
Country.id,Country.name,Country.hashFROMcountriesASCountryWHERECountry.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_countryFROMentitiesASEntity加入countries_entitiesASCountriesEntity开启 (CountriesEntity.country_id= 78 和CountriesEntity.entity_id=Entity.id) 32 32 1
作为备用计划,我可以编写代码来筛选 $blap 中的结果并提取我想要的值,但我认为会有一些方法可以在 find 命令本身中进行过滤。
【问题讨论】:
标签: php cakephp cakephp-1.3