Doktrin Fikstür Çoklu Referanslar

0 Cevap php

Ben aşağıdaki modelleri var:

class User extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn ( 'username', 'string', 20 );
        $this->hasColumn ( 'password', 'string', 40 );
        $this->hasColumn ( 'salt', 'string', 40 );
        $this->hasColumn ( 'email', 'string', 80 );
    }

    public function setUp() {
        $this->setTableName ( 'users' );

        $this->hasMany ('Message as SentMessages', array(
            'local' => 'id',
            'foreign' => 'sender_id'
        ));
        $this->hasMany ('Message as ReceivedMessages', array(
            'local' => 'id',
            'foreign' => 'recipient_id'
        ));
    }
}


class Message extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn ( 'sender_id', 'integer', 4,
                array(  'notnull'=> true,
                        'unsigned'=>true
        ));
        $this->hasColumn ( 'recipient_id', 'integer', 4,
                array(  'notnull'=> true,
                        'unsigned'=>true
        ));
        $this->hasColumn ( 'title', 'string', 20 );
        $this->hasColumn ( 'content', 'string',1000);
    }

    public function setUp() {
        $this->setTableName ( 'messages' );

        $this->hasOne ('User', array(
            'local' => 'sender_id',
            'foreign' => 'id'
            ));
        $this->hasOne ('User as Recipient', array(
            'local' => 'recipient_id',
            'foreign' => 'id'
            ));
    }
}

Ve ben Fikstür benim test ortamı otomatik yüklemek gerekir

User:
  FooUser:
    username: FooUser
    password: foobar
    email: foobar@example.com
  TestUser:
    username: Testuser
    password: foobar
    email: foobar2@example.com
Message:
  Message1:
    User: FooUser
    User: TestUser
    title: Testmessage 1
    content: This is message 1
  Message2:
    User: TestUser
    User: FooUser
    title: Testmessage 2
    content: This is message 2

This doesn't work, because I can't have 2 relationships to the same table in the fixtures. Is there a fix for this?

0 Cevap