diff options
author | Jamie Matthews <[email protected]> | 2010-10-27 18:40:22 +0100 |
---|---|---|
committer | Jamie Matthews <[email protected]> | 2010-10-27 18:40:22 +0100 |
commit | 1180dd8b729c0382683b8d02e4bf81a5f0e9a54a (patch) | |
tree | e47610f4a3996f71c3dd506443aec62af56831ea | |
parent | 3b5f61449023ddcff3a8d026d516ae63c1920bed (diff) |
Add where_id_is method, docs and test
-rw-r--r-- | README.markdown | 4 | ||||
-rw-r--r-- | idiorm.php | 9 | ||||
-rw-r--r-- | test/test_queries.php | 6 |
3 files changed, 17 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown index 6165d82..564de02 100644 --- a/README.markdown +++ b/README.markdown @@ -106,6 +106,10 @@ By default, calling `where` with two parameters (the column name and the value) If your coding style favours clarity over brevity, you may prefer to use the `where_equal` method: this is identical to `where`. +##### 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. + ##### Less than / greater than: `where_lt`, `where_gt`, `where_lte`, `where_gte` ##### There are four methods available for inequalities: @@ -295,7 +295,7 @@ */ public function find_one($id=null) { if(!is_null($id)) { - $this->where($this->_get_id_column_name(), $id); + $this->where_id_is($id); } $this->limit(1); $statement = $this->_run(); @@ -543,6 +543,13 @@ } /** + * Special method to query the table by its primary key + */ + public function where_id_is($id) { + return $this->where($this->_get_id_column_name(), $id); + } + + /** * Add a WHERE ... LIKE clause to your query. */ public function where_like($column_name, $value) { diff --git a/test/test_queries.php b/test/test_queries.php index d5c3422..f3a3f40 100644 --- a/test/test_queries.php +++ b/test/test_queries.php @@ -24,9 +24,13 @@ $expected = "SELECT * FROM `widget` LIMIT 1"; Tester::check_equal("Basic unfiltered find_one query", $expected); + ORM::for_table('widget')->where_id_is(5)->find_one(); + $expected = "SELECT * FROM `widget` WHERE `id` = '5' LIMIT 1"; + Tester::check_equal("where_id_is method", $expected); + ORM::for_table('widget')->find_one(5); $expected = "SELECT * FROM `widget` WHERE `id` = '5' LIMIT 1"; - Tester::check_equal("Filtering on ID", $expected); + Tester::check_equal("Filtering on ID passed into find_one method", $expected); ORM::for_table('widget')->count(); $expected = "SELECT COUNT(*) AS `count` FROM `widget`"; |