I have tried to get a products recordset from MySQL with the Doctrine ORM. I have to select a group of records using a regexp where the category field value can contain these values:
categories
12/43/45/101/109
OR
categories
1/12/43/45/101/109
OR
categories
43/45/101/109/12
This is my doctrine code:
$id = 12
$dq = Doctrine_Query::create ()
-> from ( 'Products p' )
-> leftJoin("p.ProductsData pd WITH pd.language_id = $locale")
-> leftJoin("p.ProductsAttributesGroups pag")
-> where('p.enabled = ?', 1)
-> andWhere ( "(categories REGEXP \"^$id[\\\]*\" OR " .
"categories REGEXP \"^[\\\]$id*\" OR " .
"categories REGEXP \"^[\\\]$id[\\\]*)\")" )
-> orderBy('position asc');
I have the $id
variable and I need to select all the records where this $CATID
is present. I cannot use a MySQL relationship and/or joins.
The simple solution in my case was this one:
// Get the category selected in the products table where the categories have been written in this way: \\12\\224\\85\\53
$reg1 = "categories like '".$id."/%'";
$reg2 = "categories like '%/".$id."'";
$reg3 = "categories like '%/".$id."/%'";
$dq->andWhere ( "($reg1 OR $reg2 OR $reg3)");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.