Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2+条令关联错误:类游戏没有名为home的关联_Php_Mysql_Symfony_Doctrine Orm_Doctrine - Fatal编程技术网

Php Symfony2+条令关联错误:类游戏没有名为home的关联

Php Symfony2+条令关联错误:类游戏没有名为home的关联,php,mysql,symfony,doctrine-orm,doctrine,Php,Mysql,Symfony,Doctrine Orm,Doctrine,以下是MySQL表的列和行: 我正在尝试使用Team.id内部加入game.home和game.away,但我得到了错误:error:Class Travel\Bundle\TravelBundle\Entity\game没有名为home的关联我做错了什么 以下是我想要实现的预期结果,我知道如何在MySQL中实现,但不知道Symfony和Doctrine: select t1.id as gameid, t1.season as gameseason, t1.ga

以下是MySQL表的列和行:

我正在尝试使用Team.id内部加入game.home和game.away,但我得到了错误:error:Class Travel\Bundle\TravelBundle\Entity\game没有名为home的关联我做错了什么

以下是我想要实现的预期结果,我知道如何在MySQL中实现,但不知道Symfony和Doctrine:

select 
    t1.id as gameid, 
    t1.season as gameseason, 
    t1.gametype as gametype, 
        t2.id as homeid, 
        t2.name as homename, 
        t2.abbreviation as homeabbreviation, 
        t2.type as hometype, 
        t2.image as homeimage,
            t3.id as awayid, 
            t3.name as awayname, 
            t3.abbreviation as awayabbreviation, 
            t3.type as awaytype, 
            t3.image as awayimage from Game t1 
            INNER JOIN Team t2 on t1.home  = t2.id
            INNER JOIN Team t3 on t1.away  = t3.id;
以下是我的原则实体:

Game.orm.yml:

Team.orm.yml

GameRepository.php

根据您的映射,应该如下所示:

Game.orm.yml:

你不能有多个oneToOne条目,我的意思是字符串‘oneToOne’,正如你在这里所做的一样,我编辑了我的答案,所以请检查一个oneToOne条目与两个关系:home和away
Travel\Bundle\TravelBundle\Entity\Game:
    type: entity
     OneToOne:
        targetEntity: Travel\Bundle\TravelBundle\Entity\Team
    JoinColumn:
        name: home
        referencedColumnName: id
    repositoryClass: Travel\Bundle\TravelBundle\Entity\GameRepository
    fields:
        id:
            type: integer
            id: true
        generator:
            strategy: AUTO
        home:
            type: integer  
        away:
            type: integer
        season:
            type: string
        gametype:
        type: integer
        username:
        type: string
    lifecycleCallbacks: {  }
Travel\Bundle\TravelBundle\Entity\Team:
    type: entity
    table: null
    repositoryClass: Travel\Bundle\TravelBundle\Entity\TeamRepository
    fields:
        id:
            type: integer
            id: true
            generator:
            strategy: AUTO
        name:
            type: string
            length: 255
        abbreviation:
            type: string
            length: 255
        type:
            type: string
            length: 255
        name:
            type: string
            length: 255
        image:
            type: string
            length: 255
        username:
            type: string
            length: 255
    lifecycleCallbacks:
        prePersist: [ uploadImage ]
        prePersist: [ preUpload ]
        preUpdate: [ preUpload ]
        postPersist: [ moveImage ]
        preRemove: [ removeImage ]
<?php

namespace Travel\Bundle\TravelBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * GameRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class GameRepository extends EntityRepository
{
    public function allByUsername($username)
    {
        $query = $this->getEntityManager()
        ->getRepository('TravelTravelBundle:Game')
        ->createQueryBuilder('t')
        ->select('t','g')
        ->innerJoin('t.home', 'g')
        ->setParameter('username', $username);
        $token = $query->getQuery()->getResult();
        return $token;
    }
}

?>
Travel\Bundle\TravelBundle\Entity\Game:
    type: entity
    repositoryClass: Travel\Bundle\TravelBundle\Entity\GameRepository
    oneToOne:
        home:
            targetEntity: Travel\Bundle\TravelBundle\Entity\Team
            joinColumn:
                name: home
                referencedColumnName: id
        away:
            targetEntity: Travel\Bundle\TravelBundle\Entity\Team
            joinColumn:
                name: away
                referencedColumnName: id