Shorthand for adding foreign key references to a table
authorChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 19:45:06 +0000 (15:45 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 19:45:06 +0000 (15:45 -0400)
Credit to http://github.com/maintainable/framework/commit/1b2f572c510ebfac71e9681ed9e453e7e86f2314

framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php

index 4f26e45..ea2b918 100644 (file)
@@ -149,6 +149,31 @@ class Horde_Db_Adapter_Base_TableDefinition implements ArrayAccess, IteratorAggr
     }
 
     /**
+     * Add one or several references to foreign keys
+     *
+     * This method returns <tt>self</tt>.
+     */
+    public function belongsTo($columns)
+    {
+        if (!is_array($columns)) { $columns = array($columns); }
+        foreach ($columns as $col) {
+            $this->column($col . '_id', 'integer');
+        }
+
+        return $this;
+    }
+
+    /**
+     * Alias for the belongsTo() method
+     *
+     * This method returns <tt>self</tt>.
+     */
+    public function references($columns)
+    {
+        return $this->belongsTo($columns);
+    }
+
+    /**
      * Use __call to provide shorthand column creation ($this->integer(), etc.)
      */
     public function __call($method, $arguments)