Skip to content

Commit

Permalink
Merge branch 'develop' of git://github.com/j4mie/idiorm into dev-getp…
Browse files Browse the repository at this point in the history
…dostatement
  • Loading branch information
tag committed Nov 30, 2012
2 parents 7bf605e + 7f38e9c commit 309f7b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Features
Changelog
---------

#### 1.3.0 - release XXXX-XX-XX

* Add in raw_execute - closes issue #40 [[tag](https://github.com/tag)]
* Add query logging to `delete_many` [[tag](https://github.com/tag)]
* Add `is_new` method - closes issue #85

#### 1.2.3 - release 2012-11-28

* Fix issue #78 - remove use of PHP 5.3 static call
Expand Down Expand Up @@ -401,6 +407,8 @@ The other functions (`AVG`, `MAX` and `SUM`) work in exactly the same manner. Su

#### Raw queries ####

##### Return Idiorm instances #####

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 optionally an array of parameters. The string can contain placeholders, either in question mark or named placeholder syntax, which will be used to bind the parameters to the query.

$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();
Expand All @@ -409,6 +417,12 @@ The ORM class instance(s) returned will contain data for all the columns returne

Note that using `raw_query` is advanced and possibly dangerous, and Idiorm does not make any attempt to protect you from making errors when using this method. If you find yourself calling `raw_query` often, you may have misunderstood the purpose of using an ORM, or your application may be too complex for Idiorm. Consider using a more full-featured database abstraction system.

##### Direct PDO access raw queries #####

It is possible to skip Idiorm's query building system altogether by using `raw_execute`. You will not get an Idiorm instance as a result and it is also potentially dangerous just like the method above.

$people = ORM::raw_execute('INSERT OR REPLACE INTO `widget` (`id`, `name`) SELECT `id`, `name` FROM `other_table` WHERE id = ?', array(10));

### Getting data from objects ###

Once you've got a set of records (objects) back from a query, you can access properties on those objects (the values stored in the columns in its corresponding table) in two ways: by using the `get` method, or simply by accessing the property on the object directly:
Expand Down Expand Up @@ -479,6 +493,8 @@ To add a new record, you need to first create an "empty" object instance. You th

After the object has been saved, you can call its `id()` method to find the autogenerated primary key value that the database assigned to it.

To determine if the instance you are operating on has been obtained by calling `create()` or whether it was via a query on the database you can call `is_new()` on it to get a boolean response.

#### Properties containing expressions ####

It is possible to set properties on the model that contain database expressions using the `set_expr` method.
Expand Down
17 changes: 17 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,15 @@ public function set($key, $value = null) {
$this->_set_orm_property($key, $value);
}

/**
* Set a property to a particular value on this object.
* To set multiple properties at once, pass an associative array
* as the first parameter and leave out the second parameter.
* Flags the properties as 'dirty' so they will be saved to the
* database when save() is called.
* @param string|array $key
* @param string|null $value
*/
public function set_expr($key, $value = null) {
$this->_set_orm_property($key, $value, true);
}
Expand Down Expand Up @@ -1277,6 +1286,14 @@ public function is_dirty($key) {
return isset($this->_dirty_fields[$key]);
}

/**
* Check whether the model was the result of a call to create() or not
* @return bool
*/
public function is_new() {
return $this->_is_new;
}

/**
* Save any fields which have been modified on this object
* to the database.
Expand Down

0 comments on commit 309f7b6

Please sign in to comment.