Author: jwage
Date: 2008-08-27 06:16:02 +0100 (Wed, 27 Aug 2008)
New Revision: 4843

Modified:
   branches/1.0/lib/Doctrine/Template/Listener/Sluggable.php
   branches/1.0/lib/Doctrine/Template/Sluggable.php
Log:
Adding alias support for sluggable column


Modified: branches/1.0/lib/Doctrine/Template/Listener/Sluggable.php
===================================================================
--- branches/1.0/lib/Doctrine/Template/Listener/Sluggable.php   2008-08-27 
05:12:09 UTC (rev 4842)
+++ branches/1.0/lib/Doctrine/Template/Listener/Sluggable.php   2008-08-27 
05:16:02 UTC (rev 4843)
@@ -58,9 +58,8 @@
      */
     public function preInsert(Doctrine_Event $event)
     {
-        $name = $this->_options['name'];
-
         $record = $event->getInvoker();
+        $name = $record->getTable()->getFieldName($this->_options['name']);
 
         if ( ! $record->$name) {
             $record->$name = $this->buildSlug($record);
@@ -77,9 +76,8 @@
     public function preUpdate(Doctrine_Event $event)
     {
         if (false !== $this->_options['unique']) {
-            $name = $this->_options['name'];
-    
             $record = $event->getInvoker();
+            $name = $record->getTable()->getFieldName($this->_options['name']);
 
             if ( ! $record->$name ||
             (false !== $this->_options['canUpdate'] &&
@@ -128,7 +126,7 @@
      */
     public function getUniqueSlug($record)
     {
-        $name = $this->_options['name'];
+        $name = $record->getTable()->getFieldName($this->_options['name']);
         $slugFromFields = '';
         foreach ($this->_options['fields'] as $field) {
             $slugFromFields .= $record->$field . ' ';

Modified: branches/1.0/lib/Doctrine/Template/Sluggable.php
===================================================================
--- branches/1.0/lib/Doctrine/Template/Sluggable.php    2008-08-27 05:12:09 UTC 
(rev 4842)
+++ branches/1.0/lib/Doctrine/Template/Sluggable.php    2008-08-27 05:16:02 UTC 
(rev 4843)
@@ -40,6 +40,7 @@
      * @var string
      */
     protected $_options = array('name'          =>  'slug',
+                                'alias'         =>  null,
                                 'type'          =>  'string',
                                 'length'        =>  255,
                                 'unique'        =>  true,
@@ -70,7 +71,11 @@
      */
     public function setTableDefinition()
     {
-        $this->hasColumn($this->_options['name'], $this->_options['type'], 
$this->_options['length'], $this->_options['options']);
+        $name = $this->_options['name'];
+        if ($this->_options['alias']) {
+            $name .= ' as ' . $this->_options['alias'];
+        }
+        $this->hasColumn($name, $this->_options['type'], 
$this->_options['length'], $this->_options['options']);
         
         if ($this->_options['unique'] == true && 
$this->_options['uniqueIndex'] == true && ! empty($this->_options['fields'])) {
             $indexFields = array($this->_options['name']);


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"doctrine-svn" group.
 To post to this group, send email to [email protected]
 To unsubscribe from this group, send email to [EMAIL PROTECTED]
 For more options, visit this group at 
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

Reply via email to