#1640: Foreign Keys for Self-referencing (Nest relations) not created for both
columns
------------------------+---------------------------------------------------
  Reporter:  hal        |       Owner:  romanb               
      Type:  defect     |      Status:  new                  
  Priority:  major      |   Milestone:  1.0.5                
 Component:  Relations  |     Version:  1.0.3                
Resolution:             |    Keywords:                       
  Has_test:  0          |    Mystatus:  Pending Core Response
 Has_patch:  0          |  
------------------------+---------------------------------------------------
Comment (by hal):

 OK, I have a kind of workaround, which correctly creates the FKs for the
 !UserReference table in the db, and also creates the two hasOne relations
 in the !UserReference class.

 The only drawback is that it creates a redundant hasMany relation (called
 '!UserReference') in the User table.

 {{{
 User:
   tableName: test_user
   columns:
     name: string(30)
   relations:
     Parents:
       class: User
       refClass: UserReference
       local: parent_id
       foreign: child_id
     Children:
       class: User
       refClass: UserReference
       local: child_id
       foreign: parent_id

 UserReference:
   tableName: test_reference
   columns:
     parent_id:
       type: integer
       primary: true
     child_id:
       type: integer
       primary: true
   relations:
     Parent:
       class: User
       local: parent_id
       foreign: id
     Child:
       class: User
       local: child_id
       foreign: id
 }}}

 {{{
 abstract class BaseUser extends sfDoctrineRecord
 {
   public function setTableDefinition()
   {
     $this->setTableName('test_user');
     $this->hasColumn('name', 'string', 30, array('type' => 'string',
 'length' => '30'));
   }

   public function setUp()
   {
     $this->hasMany('User as Parents', array('refClass' => 'UserReference',
                                             'local' => 'parent_id',
                                             'foreign' => 'child_id'));

     $this->hasMany('User as Children', array('refClass' =>
 'UserReference',
                                              'local' => 'child_id',
                                              'foreign' => 'parent_id'));

     $this->hasMany('UserReference', array('local' => 'id',
                                           'foreign' => 'parent_id'));
   }
 }


 abstract class BaseUserReference extends sfDoctrineRecord
 {
   public function setTableDefinition()
   {
     $this->setTableName('test_reference');
     $this->hasColumn('parent_id', 'integer', null, array('type' =>
 'integer', 'primary' => true));
     $this->hasColumn('child_id', 'integer', null, array('type' =>
 'integer', 'primary' => true));
   }

   public function setUp()
   {
     $this->hasOne('User as Parent', array('local' => 'parent_id',
                                           'foreign' => 'id'));

     $this->hasOne('User as Child', array('local' => 'child_id',
                                          'foreign' => 'id'));
   }
 }

 }}}


 Until this is fixed in the code, does anyone know if this solution will
 really work, what the drawbacks are, and whether there is a better way?

 If it has been fixed, can we discuss the solution, and formulate a good
 example that can be moved into the docs?

 Thanks

-- 
Ticket URL: <http://trac.doctrine-project.org/ticket/1640#comment:3>
Doctrine <http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper
--~--~---------~--~----~------------~-------~--~----~
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