summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaus Beerta <[email protected]>2011-06-12 07:50:25 +0200
committerSimon Holywell <[email protected]>2012-11-12 13:46:45 +0000
commit9c84398d361f12fa56546cc31d9e6d4059f3d4f5 (patch)
tree7fb7ac37a51a872a98f42fd49c777a65c4605646
parent9f9765dea96855126a21444725d819af4b523865 (diff)
Allow Deletion of multiple rows by adding WHERE ability
-rw-r--r--README.markdown6
-rw-r--r--idiorm.php15
2 files changed, 21 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index 971e685..419d9ab 100644
--- a/README.markdown
+++ b/README.markdown
@@ -521,6 +521,12 @@ Some database adapters require (or allow) an array of driver-specific configurat
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+To delete more than one object from the database, build a query:
+
+ $person = ORM::for_table('person')
+ ->where_equal('zipcode', 55555)
+ ->delete_many();
+
#### PDO Error Mode ####
diff --git a/idiorm.php b/idiorm.php
index 9513447..82b55ad 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -1335,6 +1335,21 @@
return $statement->execute($params);
}
+ /**
+ * Delete many records from the database
+ */
+ public function delete_many() {
+ // Build and return the full DELETE statement by concatenating
+ // the results of calling each separate builder method.
+ $query = $this->_join_if_not_empty(" ", array(
+ "DELETE FROM",
+ $this->_quote_identifier($this->_table_name),
+ $this->_build_where(),
+ ));
+ $statement = self::$_db->prepare($query);
+ return $statement->execute($this->_values);
+ }
+
// --------------------- //
// --- MAGIC METHODS --- //
// --------------------- //