diff options
-rw-r--r-- | README.markdown | 4 | ||||
-rw-r--r-- | idiorm.php | 7 | ||||
-rw-r--r-- | test/test_queries.php | 4 |
3 files changed, 14 insertions, 1 deletions
diff --git a/README.markdown b/README.markdown index 2c77fa8..461a41a 100644 --- a/README.markdown +++ b/README.markdown @@ -102,12 +102,14 @@ These limits are deliberate: these are by far the most commonly used criteria, a Some support for more complex conditions and queries is provided by the `where_raw` and `raw_select` methods (see below). If you find yourself regularly requiring more functionality than Idiorm can provide, it may be time to consider using a more full-featured ORM. -##### Equality: `where` and `where_equal` ##### +##### Equality: `where`, `where_equal`, `where_not_equal` ##### By default, calling `where` with two parameters (the column name and the value) will combine them using an equals operator (`=`). For example, calling `where('name', 'Fred')` will result in the clause `WHERE name = "Fred"`. If your coding style favours clarity over brevity, you may prefer to use the `where_equal` method: this is identical to `where`. +The `where_not_equal` method adds a `WHERE column != "value"` clause to your query. + ##### Shortcut: `where_id_is` ##### This is a simple helper method to query the table by primary key. Respects the ID column specified in the config. @@ -583,6 +583,13 @@ } /** + * Add a WHERE column != value clause to your query. + */ + public function where_not_equal($column_name, $value) { + return $this->_add_simple_where($column_name, '!=', $value); + } + + /** * Special method to query the table by its primary key */ public function where_id_is($id) { diff --git a/test/test_queries.php b/test/test_queries.php index f3a3f40..c02e3d1 100644 --- a/test/test_queries.php +++ b/test/test_queries.php @@ -44,6 +44,10 @@ $expected = "SELECT * FROM `widget` WHERE `name` = 'Fred' AND `age` = '10' LIMIT 1"; Tester::check_equal("Multiple WHERE clauses", $expected); + ORM::for_table('widget')->where_not_equal('name', 'Fred')->find_many(); + $expected = "SELECT * FROM `widget` WHERE `name` != 'Fred'"; + Tester::check_equal("where_not_equal method", $expected); + ORM::for_table('widget')->where_like('name', '%Fred%')->find_one(); $expected = "SELECT * FROM `widget` WHERE `name` LIKE '%Fred%' LIMIT 1"; Tester::check_equal("where_like method", $expected); |