6

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%"');
ton.yeung
  • 4,793
  • 6
  • 41
  • 72

1 Answers1

7

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.

Housni
  • 963
  • 1
  • 10
  • 23
  • where syntax of conditions in Lithium can be find? – Crusader Jul 09 '13 at 11:54
  • [Lithium tests](https://github.com/UnionOfRAD/lithium/blob/master/tests/cases/data/source/DatabaseTest.php) are the best way to learn. The source is extremely well tested and if you ever have problems that you really can't solve on your own, I've found their [IRC channel](https://github.com/UnionOfRAD/lithium/wiki/Participate) to be helpful (when people are around). I've even solved a lot of problems just by reading their [IRC logs](http://lithify.me/en/bot/logs/li3). – Housni Aug 01 '13 at 13:59