Skip to content

Commit

Permalink
Closes issue #85 Implement is_new() in Idiorm
Browse files Browse the repository at this point in the history
  • Loading branch information
treffynnon committed Nov 29, 2012
1 parent 68bd72b commit 8083d63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Changelog

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

* Add in raw_execute - closes issue 40 [[tag](https://github.com/tag)]
* 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.1 - release 2012-11-15

Expand Down Expand Up @@ -484,6 +485,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 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
19 changes: 18 additions & 1 deletion 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 Expand Up @@ -1512,4 +1529,4 @@ protected function _str_replace_outside_quotes_cb($matches) {
/**
* A placeholder for exceptions eminating from the IdiormString class
*/
class IdiormStringException extends Exception {}
class IdiormStringException extends Exception {}

0 comments on commit 8083d63

Please sign in to comment.