Многократные Ссылки в Учениях Доктрины - PullRequest
0 голосов
/ 16 июня 2010

У меня есть следующие модели:

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'
            ));
    }
}

И мне нужны приборы для автоматической загрузки моей среды тестирования

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

Это не работает, потому что у меня не может быть 2отношения к одной и той же таблице в светильниках.Есть ли исправление для этого?

1 Ответ

1 голос
/ 17 июня 2010

Используйте псевдоним в ваших приборах, а не название модели:

Message:
  Message1:
    User: FooUser
    Recipient: TestUser
    title: Testmessage 1
    content: This is message 1
  Message2:
    User: TestUser
    Recipient: FooUser
    title: Testmessage 2
    content: This is message 2
...