本文介绍了教义课“...."没有名为“..."的关联;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你能帮我解决这个问题,因为我真的看不出这里有什么问题.

I hope you can help me with this problem because I really cannot see what is wrong here.

我有 2 个实体:RokZaPrijavuProjektaPredmet.

I have 2 entities: RokZaPrijavuProjekta AND Predmet.

RokZaPrijavuProjekta:

/**
* @ORMTable(name="rok_prijava_projekta")
* @ORMEntity(repositoryClass="JPAdminBundleRepositoryRokZaPrijavuProjektaRepository")
*/
class RokZaPrijavuProjekta
{
/**
 * @var integer $id
 *
 * @ORMColumn(name="id", type="integer")
 * @ORMId
 * @ORMGeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var integer $id_predmet
 * @ORMManyToOne(targetEntity="Predmet")
 * @ORMColumn(name="id_predmet", type="integer")
 */
private $predmet;

/**
 * @var date $od
 * @ORMColumn(name="od", type="date")
 */
private $od;

/**
 * @var date $do
 * @ORMColumn(name="do", type="date")
 */
private $do;

/**
 * @var string $info
 * @ORMColumn(name="info", type="string", length=120)
 */
private $info;
}

Predmet 实体代码:

/**
 * @ORMTable(name="predmeti")
 * @ORMEntity(repositoryClass="JPAdminBundleRepositoryPredmetRepository")
 */
class Predmet
{
/**
 * @var integer $id
 * @ORMColumn(name="id", type="integer")
 * @ORMId
 * @ORMGeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string $sifra
 * @ORMColumn(name="sifra", type="string", length=64)
 */
private $sifra;

/**
 * @var boolean $vidljiv
 * @ORMColumn(name="vidljiv", type="boolean")
 */
private $vidljiv;
}

存储库方法:

$q = $this->createQueryBuilder('r')
->select('rzpp')
->where('rzpp.predmet = :predmet')
->from('JPAdminBundle:RokZaPrijavuProjekta', 'rzpp')
->leftJoin("rzpp.predmet", "p")
->setParameter('predmet', $predmet)
->getQuery();

所有类成员的 getter 和 setter 都已正确定义.

Both getters and setters for all class members are defined properly.

现在,RokZaPrijavuProjekta"具有对Predmet"的外键引用,因此这些RokZaPrijavuProjekta"中的许多都可以具有相同的Predmet".

Now, "RokZaPrijavuProjekta" has a foreign-key reference to "Predmet", so many of these "RokZaPrijavuProjekta" can have the same "Predmet".

我想为此创建单向多对一关系,但不断抛出异常:

I want to create unidirectional ManyToOne relation for this purpose but keep getting exception thrown:

类 JPAdminBundleEntityRokZaPrijavuProjekta 没有名为 predmet 的关联

我翻遍了 Doctrine 文档,但发现这是定义单向多对一关系的首选方式.

I went all over Doctrine documentation, but found that this is the preferred way to define unidirectional many-to-one relation.

您知道这里可能存在什么问题吗?

Do you have any idea what might be a problem here?

  • 添加了 Predmet 实体代码...
  • 添加了存储库方法

非常感谢!

问候,约万

推荐答案

可以展示 Predmet 实体代码吗?

Can you show Predmet entity code?

或者只是试试这个代码:

Or just try out this code:

// RokZaPrijavuProjekta
/**
 * @ORMManyToOne(targetEntity="Predmet", inversedBy="rokzaprojects")
 */
protected $predmet;


//Predmet
/**
 * @ORMOneToMany(targetEntity="RokZaPrijavuProjekta", mappedBy="predmet")
 */
protected $rokzaprojects;

这篇关于教义课“...."没有名为“..."的关联;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 02:06