i new cake php . have 2 tables
- ce_landing
- ce_stat
structure
ce_stat
id keyword click 1 keyword1 24 2 keyword2 2 3 keyword3 6 ce_landing
id page_keyword 1 keyword1,check,keyword3 2 keyword2,usa,alphanumeric i want fetch records ce_landing.page_keyword present in ce_stat.keyword. using in cake php model
public $hasmany = array( 'stat' => array( 'classname' => 'stat', 'foreignkey' => 'keywor', 'dependent' => false, 'conditions' => array('stat.keyword like' => '%landing.page_keywords%'), 'group' => '', 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderquery' => '', 'counterquery' => '' ) ); but generated sql query like
sql query: select
stat.id,stat.customer_id,stat.account,stat.campaign_id,stat.campaign,stat.keyword,stat.ad_grp_id,stat.ad_grp,stat.impressions,stat.clicks,stat.cost,stat.qualityscore,stat.keywordstate,stat.date_from,stat.date_to,stat.user_id,stat.created,stat.modified,stat.keyworeb_adwords.ce_statsstatstat.keyword'%landing.page_keywords%' ,stat.keyword= ('559f479a-82ac-4e3d-8c24-19b5c0a8011f')
so returns null data because of , stat.keyword =('559f479a-82ac-4e3d-8c24-19b5c0a8011f') conditions.
update
what want records ce_landing total clicks according keywords present . i.e record 1 in ce_landing. i'll result
id page_keyword clicks 1 keyword1,check,keyword3 30 2 keyword2,usa,alphanumeric 2
you needs sql statement equivalent to:
select ce_landing.id, ce_landing.page_keyword, sum(ce_stat.click) total_clicks ce_landing left join ce_stat on find_in_set(keyword,page_keyword)>0 group ce_landing.id, ce_landing.page_keyword; which not translate cakephp's find method. use query method implement.
$this->landing->query("select landing.id, landing.page_keyword, sum(ce_stat.click) total_clicks ce_landing landing left join ce_stat on find_in_set(keyword,page_keyword)>0 group landing.id, landing.page_keyword;");
Comments
Post a Comment