Changeset 4857

Show
Ignore:
Timestamp:
08/29/08 05:42:21 (10 months ago)
Author:
guilhermeblanco
Message:

Dropped hasOne(string, string) and hasMany(string, string) in favor to hasOne(string, array) and hasMany(string, array) support. Backward compatibility (<= 0.9) is not supported anymore.

Location:
branches/1.0
Files:
36 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Table.php

    r4845 r4857  
    797797    public function bind($args, $type) 
    798798    { 
    799         $options = array(); 
     799        $options = ( ! isset($args[1])) ? array() : $args[1]; 
    800800        $options['type'] = $type; 
    801  
    802         if ( ! isset($args[1])) { 
    803             $args[1] = array(); 
    804         } 
    805  
    806         // the following is needed for backwards compatibility 
    807         if (is_string($args[1])) { 
    808             if ( ! isset($args[2])) { 
    809                 $args[2] = array(); 
    810             } elseif (is_string($args[2])) { 
    811                 $args[2] = (array) $args[2]; 
    812             } 
    813  
    814             $classes = array_merge($this->_options['parents'], array($this->getComponentName())); 
    815  
    816             $e = explode('.', $args[1]); 
    817             if (in_array($e[0], $classes)) { 
    818                 if ($options['type'] >= Doctrine_Relation::MANY) { 
    819                     $options['foreign'] = $e[1]; 
    820                 } else { 
    821                     $options['local'] = $e[1]; 
    822                 } 
    823             } else { 
    824                 $e2 = explode(' as ', $args[0]); 
    825                 if ($e[0] !== $e2[0] && ( ! isset($e2[1]) || $e[0] !== $e2[1])) { 
    826                     $options['refClass'] = $e[0]; 
    827                 } 
    828  
    829                 $options['foreign'] = $e[1]; 
    830             } 
    831  
    832             $options = array_merge($args[2], $options); 
    833         } else { 
    834             $options = array_merge($args[1], $options); 
    835         } 
    836801 
    837802        $this->_parser->bind($args[0], $options); 
  • branches/1.0/tests/models/App.php

    r2353 r4857  
    77    } 
    88    public function setUp() { 
    9         $this->hasOne('User', 'User.id'); 
    10         $this->hasMany('App_Category as Category', 'App_Category.id'); 
     9        $this->hasOne('User', array( 
     10            'local' => 'user_id', 'foreign' => 'id' 
     11        )); 
     12 
     13        $this->hasOne('App_Category as Category', array( 
     14            'local' => 'app_category_id', 
     15            'foreign' => 'id' 
     16        )); 
    1117    }         
    1218} 
  • branches/1.0/tests/models/App_Category.php

    r2353 r4857  
    66    } 
    77    public function setUp() { 
    8         $this->hasMany('App', 'App.app_category_id'); 
    9         $this->hasMany('App_Category as Parent', 'App_Category.parent_id'); 
     8        $this->hasMany('App', array( 
     9            'local' => 'id', 
     10            'foreign' => 'app_category_id' 
     11        )); 
     12 
     13        $this->hasMany('App_Category as Parent', array( 
     14            'local' => 'parent_id', 
     15            'foreign' => 'id' 
     16        )); 
    1017    } 
    1118} 
  • branches/1.0/tests/models/App_User.php

    r2353 r4857  
    1111    } 
    1212    public function setUp() { 
    13         $this->hasMany('App', 'App.user_id'); 
     13        $this->hasMany('App', array( 
     14            'local' => 'id', 
     15            'foreign' => 'user_id' 
     16        )); 
    1417    }     
    1518} 
  • branches/1.0/tests/models/CPK_Association.php

    r2353 r4857  
    22class CPK_Association extends Doctrine_Record { 
    33    public function setTableDefinition() { 
    4         $this->hasColumn('test1_id', 'integer', 11, 'primary'); 
    5         $this->hasColumn('test2_id', 'integer', 11, 'primary'); 
     4        $this->hasColumn('test1_id', 'integer', 11, array('primary' => true)); 
     5        $this->hasColumn('test2_id', 'integer', 11, array('primary' => true)); 
    66    } 
    77} 
  • branches/1.0/tests/models/CPK_Test.php

    r2353 r4857  
    55    } 
    66    public function setUp() { 
    7         $this->hasMany('CPK_Test2 as Test', 'CPK_Association.test2_id'); 
     7        $this->hasMany('CPK_Test2 as Test', array( 
     8            'local' => 'test1_id', 
     9            'foreign' => 'test2_id', 
     10            'refClass' => 'CPK_Association' 
     11        )); 
    812    } 
    913} 
  • branches/1.0/tests/models/CPK_Test2.php

    r2353 r4857  
    55    } 
    66    public function setUp() { 
    7         $this->hasMany('CPK_Test as Test', 'CPK_Association.test1_id'); 
     7        $this->hasMany('CPK_Test as Test', array( 
     8            'local' => 'test2_id', 
     9            'foreign' => 'test1_id', 
     10            'refClass' => 'CPK_Association' 
     11        )); 
    812    } 
    913} 
  • branches/1.0/tests/models/Data_File.php

    r2353 r4857  
    66    } 
    77    public function setUp() { 
    8         $this->hasOne('File_Owner', 'Data_File.file_owner_id'); 
     8        $this->hasOne('File_Owner', array('local' => 'file_owner_id', 'foreign' => 'id')); 
    99    } 
    1010} 
  • branches/1.0/tests/models/File_Owner.php

    r2353 r4857  
    55    } 
    66        public function setUp() { 
    7         $this->hasOne('Data_File', 'Data_File.file_owner_id'); 
     7        $this->hasOne('Data_File', array('local' => 'id', 'foreign' => 'file_owner_id')); 
    88    } 
    99} 
  • branches/1.0/tests/models/ForeignKeyTest2.php

    r2353 r4857  
    77        $this->hasColumn('foreignkey', 'integer'); 
    88        
    9         $this->hasOne('ForeignKeyTest', 'ForeignKeyTest2.foreignkey'); 
     9        $this->hasOne('ForeignKeyTest', array( 
     10            'local' => 'foreignKey', 'foreign' => 'id' 
     11        )); 
    1012    } 
    1113} 
  • branches/1.0/tests/models/Forum_Category.php

    r2353 r4857  
    88    } 
    99    public function setUp() { 
    10         $this->hasMany('Forum_Category as Subcategory', 'Subcategory.parent_category_id'); 
    11         $this->hasOne('Forum_Category as Parent', 'Forum_Category.parent_category_id'); 
    12         $this->hasOne('Forum_Category as Rootcategory', 'Forum_Category.root_category_id'); 
     10        $this->hasMany('Forum_Category as Subcategory', array( 
     11            'local' => 'id', 
     12            'foreign' => 'parent_category_id' 
     13        )); 
     14         
     15        $this->hasOne('Forum_Category as Parent', array( 
     16            'local' => 'parent_category_id', 
     17            'foreign' => 'id' 
     18        )); 
     19 
     20        $this->hasOne('Forum_Category as Rootcategory', array( 
     21            'local' => 'root_category_id', 
     22            'foreign' => 'id' 
     23        )); 
    1324    } 
    1425} 
  • branches/1.0/tests/models/Log_Entry.php

    r2353 r4857  
    55        $this->hasColumn('status_id', 'integer'); 
    66    } 
     7     
    78    public function setUp() { 
    8         $this->hasOne('Log_Status', 'Log_Entry.status_id'); 
     9        $this->hasOne('Log_Status', array( 
     10            'local' => 'status_id', 'foreign' => 'id' 
     11        )); 
    912    } 
    1013} 
  • branches/1.0/tests/models/MyOneThing.php

    r2353 r4857  
    55        $this->hasColumn('user_id', 'integer'); 
    66    } 
     7 
    78    public function setUp() { 
    8                 $this->hasMany('MyUserOneThing', 'MyUserOneThing.one_thing_id'); 
     9                $this->hasMany('MyUserOneThing', array( 
     10            'local' => 'id', 'foreign' => 'one_thing_id' 
     11        )); 
     12         
     13        $this->hasOne('MyUser', array( 
     14            'local' => 'user_id', 'foreign' => 'id' 
     15        )); 
    916    } 
    1017} 
  • branches/1.0/tests/models/MyOtherThing.php

    r2353 r4857  
    66    } 
    77    public function setUp() { 
    8                 $this->hasMany('MyUserOtherThing', 'MyUserOtherThing.other_thing_id'); 
     8                $this->hasMany('MyUserOtherThing', array( 
     9            'local' => 'id', 'foreign' => 'other_thing_id' 
     10        )); 
     11         
     12        $this->hasOne('MyUser', array( 
     13            'local' => 'user_id', 'foreign' => 'id' 
     14        )); 
    915    } 
    1016} 
  • branches/1.0/tests/models/MysqlGroup.php

    r2353 r4857  
    55    { 
    66        $this->hasColumn('name', 'string', null); 
    7  
    8         $this->hasMany('MysqlUser', 'MysqlGroupMember.user_id'); 
     7    } 
     8     
     9    public function setUp() 
     10    { 
     11        $this->hasMany('MysqlUser', array( 
     12            'local' => 'group_id',  
     13            'foreign' => 'user_id', 
     14            'refClass' => 'MysqlGroupMember' 
     15        )); 
    916    } 
    1017} 
  • branches/1.0/tests/models/MysqlGroupMember.php

    r2353 r4857  
    44    public function setTableDefinition()  
    55    { 
    6         $this->hasColumn('group_id', 'integer', null, 'primary'); 
    7         $this->hasColumn('user_id', 'integer', null, 'primary'); 
     6        $this->hasColumn('group_id', 'integer', null, array('primary' => true)); 
     7        $this->hasColumn('user_id', 'integer', null, array('primary' => true)); 
    88    } 
    99} 
  • branches/1.0/tests/models/MysqlUser.php

    r2353 r4857  
    55    { 
    66        $this->hasColumn('name', 'string', null); 
    7  
    8         $this->hasMany('MysqlGroup', 'MysqlGroupMember.group_id'); 
     7    } 
     8     
     9    public function setUp() 
     10    { 
     11        $this->hasMany('MysqlGroup', array( 
     12            'local' => 'user_id', 
     13            'foreign' => 'group_id', 
     14            'refClass' => 'MysqlGroupMember' 
     15        )); 
    916    } 
    1017} 
  • branches/1.0/tests/models/MyUser.php

    r4033 r4857  
    99    public function setUp() 
    1010    { 
    11                   $this->hasMany('MyOneThing', 'MyOneThing.user_id'); 
    12                   $this->hasMany('MyOtherThing', 'MyOtherThing.user_id'); 
     11                  $this->hasMany('MyOneThing', array( 
     12            'local' => 'id', 'foreign' => 'user_id' 
     13          )); 
     14 
     15                  $this->hasMany('MyOtherThing', array( 
     16            'local' => 'id', 'foreign' => 'user_id' 
     17          )); 
    1318    } 
    1419} 
  • branches/1.0/tests/models/MyUserOneThing.php

    r2353 r4857  
    55        $this->hasColumn('one_thing_id', 'integer'); 
    66    } 
     7     
     8     
     9    public function setUp() 
     10    { 
     11        $this->hasOne('MyUser', array( 
     12            'local' => 'user_id', 'foreign' => 'id' 
     13        )); 
     14         
     15        $this->hasOne('MyOneThing', array( 
     16            'local' => 'one_thing_id', 'foreign' => 'id' 
     17        )); 
     18    } 
    719} 
  • branches/1.0/tests/models/MyUserOtherThing.php

    r2353 r4857  
    55        $this->hasColumn('other_thing_id', 'integer'); 
    66    } 
     7     
     8     
     9    public function setUp() 
     10    { 
     11        $this->hasOne('MyUser', array( 
     12            'local' => 'user_id', 'foreign' => 'id' 
     13        )); 
     14         
     15        $this->hasOne('MyOtherThing', array( 
     16            'local' => 'other_thing_id', 'foreign' => 'id' 
     17        )); 
     18    } 
    719} 
  • branches/1.0/tests/models/ORM_AccessControl.php

    r2353 r4857  
    88    public function setUp()  
    99    { 
    10         $this->hasMany('ORM_AccessGroup as accessGroups', 'ORM_AccessControlsGroups.accessGroupID'); 
     10        $this->hasMany('ORM_AccessGroup as accessGroups', array( 
     11            'local' => 'accessControlID', 'foreign' => 'accessGroupID', 'refClass' => 'ORM_AccessControlsGroups' 
     12        )); 
    1113    } 
    1214} 
  • branches/1.0/tests/models/ORM_AccessGroup.php

    r2353 r4857  
    88    public function setUp()  
    99    { 
    10         $this->hasMany('ORM_AccessControl as accessControls', 'ORM_AccessControlsGroups.accessControlID'); 
     10        $this->hasMany('ORM_AccessControl as accessControls', array( 
     11            'local' => 'accessGroupID', 'foreign' => 'accessControlID', 'refClass' => 'ORM_AccessControlsGroups' 
     12        )); 
    1113    } 
    1214} 
  • branches/1.0/tests/models/ORM_TestEntry.php

    r2353 r4857  
    1111     
    1212   public function setUp() {   
    13         $this->hasOne('ORM_TestItem', 'ORM_TestEntry.itemID');  
     13        $this->hasOne('ORM_TestItem', array( 
     14            'local' => 'itemID', 'foreign' => 'id' 
     15        )); 
    1416   } 
    1517} 
  • branches/1.0/tests/models/ORM_TestItem.php

    r2353 r4857  
    99   public function setUp() { 
    1010 
    11         $this->hasOne('ORM_TestEntry', 'ORM_TestEntry.itemID');  
     11        $this->hasOne('ORM_TestEntry', array( 
     12            'local' => 'id', 'foreign' => 'itemID' 
     13        )); 
    1214   }  
    1315} 
  • branches/1.0/tests/models/PackageVersion.php

    r2353 r4857  
    77    public function setUp() 
    88    { 
    9         $this->hasOne('Package', 'PackageVersion.package_id'); 
    10         $this->hasMany('PackageVersionNotes as Note', 'PackageVersionNotes.package_version_id'); 
     9        $this->hasOne('Package', array('local' => 'package_id', 'foreign' => 'id')); 
     10        $this->hasMany('PackageVersionNotes as Note', array( 
     11            'local' => 'id', 'foreign' => 'package_version_id' 
     12        )); 
    1113    } 
    1214} 
  • branches/1.0/tests/models/PackageVersionNotes.php

    r2353 r4857  
    99    public function setUp() 
    1010    { 
    11         $this->hasOne('PackageVersion', 'PackageVersionNotes.package_version_id'); 
     11        $this->hasOne('PackageVersion', array( 
     12            'local' => 'package_version_id', 'foreign' => 'id' 
     13        )); 
    1214    } 
    1315} 
  • branches/1.0/tests/models/Photo.php

    r2353 r4857  
    22class Photo extends Doctrine_Record { 
    33    public function setUp() { 
    4         $this->hasMany('Tag', 'Phototag.tag_id'); 
     4        $this->hasMany('Tag', array( 
     5            'local' => 'photo_id', 
     6            'foreign' => 'tag_id', 
     7            'refClass' => 'Phototag' 
     8        )); 
    59    } 
    610    public function setTableDefinition() { 
  • branches/1.0/tests/models/Phototag.php

    r2353 r4857  
    22class Phototag extends Doctrine_Record { 
    33    public function setTableDefinition() { 
    4         $this->hasColumn('photo_id', 'integer'); 
    5         $this->hasColumn('tag_id', 'integer'); 
     4        $this->hasColumn('photo_id', 'integer', 11, array('primary' => true)); 
     5        $this->hasColumn('tag_id', 'integer', 11, array('primary' => true)); 
    66    } 
    77} 
  • branches/1.0/tests/models/QueryTest_Entry.php

    r4829 r4857  
    1919    public function setUp() 
    2020    { 
    21         $this->hasOne('QueryTest_User as author', 'QueryTest_Entry.authorId'); 
     21        $this->hasOne('QueryTest_User as author', array( 
     22            'local' => 'authorId', 'foreign' => 'id' 
     23        )); 
    2224    } 
    2325} 
  • branches/1.0/tests/models/QueryTest_Rank.php

    r2353 r4857  
    1414                array('notnull', 'default' => ' ', 'regexp' => '/^[a-zA-Z0-9_\-]+\.(jpg|gif|png)$/D'));         
    1515    } 
     16 
    1617    public function setUp() 
    1718    { 
    18         $this->hasMany('QueryTest_User as users', 'QueryTest_UserRank.userId'); 
     19        $this->hasMany('QueryTest_User as users', array( 
     20            'local' => 'rankId', 'foreign' => 'userId', 'refClass' => 'QueryTest_UserRank' 
     21        )); 
    1922    } 
    2023} 
  • branches/1.0/tests/models/QueryTest_User.php

    r2963 r4857  
    1515    public function setUp() 
    1616    { 
    17         $this->hasOne('QueryTest_Rank as visibleRank', 'QueryTest_User.visibleRankId'); 
    18         $this->hasMany('QueryTest_Rank as ranks', 'QueryTest_UserRank.rankId'); 
     17        $this->hasOne('QueryTest_Rank as visibleRank', array( 
     18            'local' => 'visibleRankId', 'foreign' => 'id' 
     19        )); 
     20 
     21        $this->hasMany('QueryTest_Rank as ranks', array( 
     22            'local' => 'userId', 'foreign' => 'rankId', 'refClass' => 'QueryTest_UserRank' 
     23        )); 
    1924    } 
    2025} 
  • branches/1.0/tests/models/QueryTest_UserRank.php

    r2353 r4857  
    44    public function setTableDefinition() 
    55    {         
    6         $this->hasColumn('rankId', 'integer', 4, array('primary')); 
    7         $this->hasColumn('userId', 'integer', 4, array('primary')); 
     6        $this->hasColumn('rankId', 'integer', 4, array('primary' => true)); 
     7        $this->hasColumn('userId', 'integer', 4, array('primary' => true)); 
    88    } 
    99} 
  • branches/1.0/tests/models/Record_City.php

    r2353 r4857  
    66        $this->hasColumn('district_id', 'integer'); 
    77    } 
     8     
    89    public function setUp() { 
    9         $this->hasOne('Record_Country as Country', 'Record_City.country_id'); 
    10         $this->hasOne('Record_District as District', 'Record_City.district_id'); 
     10        $this->hasOne('Record_Country as Country', array( 
     11            'local' => 'country_id', 'foreign' => 'id' 
     12        )); 
     13 
     14        $this->hasOne('Record_District as District', array( 
     15            'local' => 'district_id', 'foreign' => 'id' 
     16        )); 
    1117    } 
    1218} 
  • branches/1.0/tests/models/Record_Country.php

    r2353 r4857  
    55    } 
    66    public function setUp() { 
    7         $this->hasMany('Record_City as City', 'City.country_id'); 
     7        $this->hasMany('Record_City as City', array( 
     8            'local' => 'id', 
     9            'foreign' => 'country_id' 
     10        )); 
    811    } 
    912} 
  • branches/1.0/tests/models/Tag.php

    r2353 r4857  
    22class Tag extends Doctrine_Record { 
    33    public function setUp() { 
    4         $this->hasMany('Photo', 'Phototag.photo_id'); 
     4        $this->hasMany('Photo', array( 
     5            'local' => 'tag_id', 
     6            'foreign' => 'photo_id', 
     7            'refClass' => 'Phototag' 
     8        )); 
    59    } 
    610    public function setTableDefinition() { 
  • branches/1.0/tests/models/TreeLeaf.php

    r2353 r4857  
    77        $this->hasColumn('parent_id', 'integer'); 
    88    } 
     9 
    910    public function setUp()  
    1011    { 
    11         $this->hasOne('TreeLeaf as Parent', 'TreeLeaf.parent_id'); 
    12         $this->hasMany('TreeLeaf as Children', 'TreeLeaf.parent_id'); 
     12        $this->hasOne('TreeLeaf as Parent', array( 
     13            'local' => 'parent_id', 'foreign' => 'id' 
     14        )); 
     15         
     16        $this->hasMany('TreeLeaf as Children', array( 
     17            'local' => 'id', 'foreign' => 'parent_id' 
     18        )); 
    1319    } 
    1420}