summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-10-25 20:21:52 +0100
committerJamie Matthews <[email protected]>2010-10-25 20:21:52 +0100
commit011b55119b56023224781be01d27043c5a1454ab (patch)
tree43719d69de51fb0f9cf6b0583ba53b9066d63919 /idiorm.php
parentb54973b4e0f157c79b2d0e2062d233ba2260b1a8 (diff)
Add table_alias method to provide ability to alias the main table in SELECT queries
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/idiorm.php b/idiorm.php
index c65fdd5..6087705 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -80,6 +80,9 @@
// The name of the table the current ORM instance is associated with
protected $_table_name;
+ // Alias for the table to be used in SELECT queries
+ protected $_table_alias = null;
+
// Values to be bound to the query
protected $_values = array();
@@ -362,6 +365,14 @@
}
/**
+ * Add a an alias for the main table to be used in SELECT queries
+ */
+ public function table_alias($alias) {
+ $this->_table_alias = $alias;
+ return $this;
+ }
+
+ /**
* Internal method to add an unquoted expression to the set
* of columns returned by the SELECT query. The second optional
* argument is the alias to return the expression as.
@@ -668,7 +679,11 @@
*/
protected function _build_select_start() {
$result_columns = join(', ', $this->_result_columns);
- return "SELECT {$result_columns} FROM " . $this->_quote_identifier($this->_table_name);
+ $fragment = "SELECT {$result_columns} FROM " . $this->_quote_identifier($this->_table_name);
+ if (!is_null($this->_table_alias)) {
+ $fragment .= " " . $this->_quote_identifier($this->_table_alias);
+ }
+ return $fragment;
}
/**