summaryrefslogtreecommitdiff
path: root/README.markdown
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-02-13 13:59:35 +0000
committerJamie Matthews <[email protected]>2010-02-13 13:59:35 +0000
commit64dca311d486483670efb5185ccb0345ead18506 (patch)
tree0be792fdc28797d3b5c2e6e6946ea9b5e2d68d09 /README.markdown
parentf912c616d6894e7aea4300cfdbe610b0924ce1ba (diff)
Improved examples in README
Diffstat (limited to 'README.markdown')
-rw-r--r--README.markdown18
1 files changed, 9 insertions, 9 deletions
diff --git a/README.markdown b/README.markdown
index 135b062..ca0b0d5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -62,13 +62,13 @@ Any method chain that ends in `find_one()` will return either a *single* instanc
To find a single record where the `name` column has the value "Fred Bloggs":
- ORM::for_table('person')->where('name', 'Fred Bloggs')->find_one();
+ $person = ORM::for_table('person')->where('name', 'Fred Bloggs')->find_one();
This roughly translates into the following SQL: `SELECT * FROM person WHERE name = "Fred Bloggs"`
To find a single record by ID, you can pass the ID directly to the `find_one` method:
- ORM::for_table('person')->find_one(5);
+ $person = ORM::for_table('person')->find_one(5);
#### Multiple records ####
@@ -76,11 +76,11 @@ Any method chain that ends in `find_many()` will return an *array* of ORM class
To find all records in the table:
- ORM::for_table('person')->find_many();
+ $people = ORM::for_table('person')->find_many();
To find all records where the `gender` is `female`:
- ORM::for_table('person')->where('gender', 'female')->find_many();
+ $females = ORM::for_table('person')->where('gender', 'female')->find_many();
#### WHERE clauses ####
@@ -92,7 +92,7 @@ By default, calling `where` with two parameters (the column name and the value)
To add a `WHERE ... LIKE` clause, use:
- ORM::for_table('person')->where_like('Name', '%fred%')->find_many();
+ $people = ORM::for_table('person')->where_like('Name', '%fred%')->find_many();
#### Raw WHERE clauses ####
@@ -100,7 +100,7 @@ If you require a more complex query, you can use the `where_raw` method to speci
This method may be chained with other methods such as `offset`, `limit` and `order_by_(*)`, but it may NOT be chained with other calls to `where`. If other `where` clauses are added, they will simply be ignored in the resulting query.
- ORM::for_table('person')->where_raw('name = ? AND (age = ? OR age = ?)', array('Fred', 5, 10))->order_by_asc('name');
+ $people = ORM::for_table('person')->where_raw('name = ? AND (age = ? OR age = ?)', array('Fred', 5, 10))->order_by_asc('name')->find_many();
Note that this method only supports "question mark placeholder" syntax, and NOT "named placeholder" syntax.
@@ -108,19 +108,19 @@ Note that this method only supports "question mark placeholder" syntax, and NOT
The `limit` and `offset` methods map pretty closely to their SQL equivalents.
- ORM::for_table('person')->where('gender', 'female')->limit(5)->offset(10)->find_many();
+ $people = ORM::for_table('person')->where('gender', 'female')->limit(5)->offset(10)->find_many();
#### ORDER BY ####
Two methods are provided to add `ORDER BY` clauses to your query. These are `order_by_desc` and `order_by_asc`, each of which takes a column name to sort by.
- ORM::for_table('person')->order_by_asc('gender')->order_by_desc('name')->find_many();
+ $people = ORM::for_table('person')->order_by_asc('gender')->order_by_desc('name')->find_many();
#### Raw queries ####
If you need to perform more complex queries, you can completely specify the query to execute by using the `raw_query` method. This method takes a string and an array of parameters. The string should contain placeholders, either in question mark or named placeholder syntax, which will be used to bind the parameters to the query.
- ORM::for_table('person')->raw_query('SELECT p.* FROM person p JOIN role r ON p.role_id = r.id WHERE r.name = :role', array('role' => 'janitor')->find_many();
+ $people = ORM::for_table('person')->raw_query('SELECT p.* FROM person p JOIN role r ON p.role_id = r.id WHERE r.name = :role', array('role' => 'janitor')->find_many();
The ORM class instance(s) returned will contain data for all the columns returned by the query. Note that you still must call `for_table` to bind the instances to a particular table, even though there is nothing to stop you from specifying a completely different table in the query. This is because if you wish to later called `save`, the ORM will need to know which table to update.