Thanks for your quick reply. Adding the extra field to where() fixed the issue I was having. The where() function now looks like:
$this->EE->rem4_domain->where("$domain LIKE CONCAT('%', REPLACE(name, '_', '\\_'))", NULL, FALSE);
I’m using EE2 Public Beta on this project, so I ran into another unexpected interaction. CI as configured in EE2 uses a database table prefix, so it ends up rewriting the WHERE clause as:
WHERE 'www.my.exp_example.com' LIKE
I didn’t see an easy way around this, so I ended up writing the query manually using the query() method.
I never could get order_by() to work for another query. My order_by statement looks like:
$ids = array(1, 5, 20, 3, 14, 16);
$this->property->order_by('FIELD(properties.id, ' . implode(',', $ids) . ' )');
No matter what I did, I couldn’t get CI to leave the array of ids alone. I ended up writing a quick and dirty DMZ extension to handle order by field expressions, using some tricks I found in DMZ’s source. The order_by statement is now much simpler. It looks like:
$this->property->order_by_field('properties.id', $ids);
Here’s the extension. It works for me, maybe it’ll work for you.
<?php
# DMZ extension adds order_by_field method
# usage:
# $dmz->order_by_field($fieldname, $array, $escape = TRUE)
# creates ORDER BY FIELD('fieldname', $array_1, $array_2, ... $array_n)
# escapes array entries if $escape is set
# assumes DMZ 1.6.0 or greater
# written by Jack Scott <[email protected]> Jan 20 2010
# copyright (C) 2010 eMarketSouth LLC
# released under the same license as DataMapper Overzealous Edition
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
class DMZ_order_field {
function order_by_field($object, $field, $array, $escape = TRUE)
{
if (! is_array($array))
{
# $array not an array, return now
return $object;
}
$db =& $object->db;
# need to escape array contents?
if ($escape)
{
$array_escape = array_map(array($db, 'escape'), $array);
}
else
{
$array_escape =& $array;
}
# generate the ORDER clause, pass it to $db object
$order = 'FIELD(' . $object->add_table_name($field) . ', ' . implode(', ', $array_escape) . ')';
# CI protect_identifiers mangles the ORDER clause - turn it off
$protect = $db->_protect_identifiers;
$db->_protect_identifiers = FALSE;
$db->order_by($order);
$db->_protect_identifiers = $protect;
return $object;
}
}
/* End of file order_field.php */