summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Holywell <[email protected]>2012-11-29 14:40:14 +0000
committerSimon Holywell <[email protected]>2012-11-29 14:40:14 +0000
commit8083d63741f91a285cf433de0fe6b36a9140d91c (patch)
treecd60ef51fba035d8169616d2bffd8e1a7d09259b
parent68bd72bb63c006e71e8d2f592ee536ff591297c1 (diff)
Closes issue #85 Implement is_new() in Idiorm
-rw-r--r--README.markdown5
-rw-r--r--idiorm.php19
2 files changed, 22 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown
index 8aa1c7d..6a5af9e 100644
--- a/README.markdown
+++ b/README.markdown
@@ -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
@@ -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.
diff --git a/idiorm.php b/idiorm.php
index 85a0632..523e157 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -1244,6 +1244,15 @@
$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);
}
@@ -1278,6 +1287,14 @@
}
/**
+ * 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.
*/
@@ -1512,4 +1529,4 @@
/**
* A placeholder for exceptions eminating from the IdiormString class
*/
- class IdiormStringException extends Exception {} \ No newline at end of file
+ class IdiormStringException extends Exception {}