Question

so I can look for concrete values by doing

        $recordset= Model::find('all', array(
            'conditions' => array(
                'condition' => $somevalue
            ) 
        ))

however, what do I do if I want to match on a partial value?
right now, I've resorted to writing the query myself, a la:

$abc = Connections::get('default')->
   read('SELECT * FROM myTable WHERE condition LIKE "%partial string%"');
Was it helpful?

Solution

Here's how I do an SQL 'like' search:

$user = User::find('all', array(
        'conditions' => array(
            'first_name' => array('like' => '%yeun%'))
        )
);

'like' being the keyword, there.

That would generate a query like:

SELECT * FROM `users` AS `Users` WHERE (`first_name` like '%yeun%');

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top