Search code examples
phpzend-frameworkpropel

Zend Properl filterBy with collate


I'm new with propel and I have one question. How I can put into filterBy collation? I need something like this:

SELECT id, name, email FROM users WHERE email COLLATE utf8_bin = "teSt@domain.com"

I need case-sensitivity search, but I can't change table schema for now. I'm trying:

$model = Model_Propel_Users::create()->filterByName('COLLATE utf8_bin ' . $name)

But it doesn't work. Anyone have ideas?

Thanks!


Solution

  • I've found solution, perhaps it will be usefull for somebody.

    First, I've added new method into model:

    public function findUser($email)
    {
        $criteria = new Criteria();
    
        $conn = Propel::getConnection();
        $cq = Model_Propel_Users::EMAIL . ' COLLATE utf8_bin LIKE ' . $conn->quote($email);
        $criteria->add(null, $cq, Criteria::CUSTOM);
        $user = Model_Propel_Users::doSelectOne($criteria);
        return $user;
    }
    

    Then just make call to get result:

    $user = Model_Propel_Users::create()->findUser($email);