如何在cakephp find方法中使用"find_in_set"

Dee*_*yal 5 cakephp

我有一个表,其中逗号分隔另一个表的id我想在cakephp中以正确的形式使用以下查询与find函数

"select * from special_offers where find_in_set('".$storeId."', stores) and user_id = '". $userId ."'";
Run Code Online (Sandbox Code Playgroud)

Shi*_*edi 12

像这样使用

$data = $this->SpecialOffer->find('all',array('conditions' => array('SpecialOffer.user_id' => $userId ,'FIND_IN_SET(\''. $storeId .'\',SpecialOffer.stores1)')));
Run Code Online (Sandbox Code Playgroud)

希望这可以帮到你

  • 我认为使用数组语法(自动转义等)会更清晰:`FIND_IN_SET(?,SpecialOffer.stores1)'=> array($ storeId)`, (2认同)