问题描述
我希望你能帮我解决这个问题,因为我真的看不到这里有什么问题。我有两个实体: RokZaPrijavuProjekta AND Predmet 。
RokZaPrijavuProjekta:
/ * *
* @ ORM\Table(name =rok_prijava_projekta)
* @ ORM\Entity(repositoryClass =JP\AdminBundle\Repository\RokZaPrijavuProjektaRepository)
* /
class RokZaPrijavuProjekta
{
/ **
* @var整数$ id
*
* @ ORM\Column(name =id type =integer)
* @ ORM\Id
* @ ORM\GeneratedValue(strategy =AUTO)
* /
private $ id;
/ **
* @var整数$ id_predmet
* @ ORM\ManyToOne(targetEntity =Predmet)
* @ ORM\Column(name =id_predmet,type =integer)
* /
private $ predmet;
/ **
* @var date $ od
* @ ORM\Column(name =od,type =date)
* /
private $ od;
/ **
* @var date $ do
* @ ORM\Column(name =do,type =date)
*
private $ do;
/ **
* @var string $ info
* @ ORM\Column(name =info,type =string,length = 120)
* /
private $ info;
}
Predmet实体代码
/ **
* @ ORM\Table(name =predmeti)
* @ ORM\Entity repositoryClass =JP\AdminBundle\Repository\PredmetRepository)
* /
class Predmet
{
/ **
* @var integer $ id
* @ ORM\Column(name =id,type =integer)
* @ ORM\Id
* @ ORM\GeneratedValue(strategy =AUTO b $ b * /
private $ id;
/ **
* @var string $ sifra
* @ ORM\Column(name =sifra,type =string,length = 64)
* /
private $ sifra;
/ **
* @var boolean $ vidljiv
* @ ORM\Column(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都被正确定义。
现在,RokZaPrijavuProjekta对Predmet有外键引用,所以这些RokZaPrijavuProjekta中有许多可以有相同的Predmet。
我想为此创建单向ManyToOne关系,但是不断收到异常:
I全部是,但是发现这是定义单向多对一关系的首选方式。
你有什么想法吗?
$ b
更新
- 添加了Predmet实体代码...
- 添加存储库方法
很多!
Regards,
Jovan
可以你显示Predmet实体代码?
或者只是试试这个代码:
// RokZaPrijavuProjekta
/ **
* @ ORM\ManyToOne(targetEntity =Predmet,inversedBy =rokzaprojects)
* /
保护$ predmet;
// Predmet
/ **
* @ ORM\OneToMany(targetEntity =RokZaPrijavuProjekta,mappedBy =predmet)
* /
protected $ rokzaprojects;
I hope you can help me with this problem because I really cannot see what is wrong here.
I have 2 entities: RokZaPrijavuProjekta AND Predmet.
RokZaPrijavuProjekta:
/**
* @ORM\Table(name="rok_prijava_projekta")
* @ORM\Entity(repositoryClass="JP\AdminBundle\Repository\RokZaPrijavuProjektaRepository")
*/
class RokZaPrijavuProjekta
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer $id_predmet
* @ORM\ManyToOne(targetEntity="Predmet")
* @ORM\Column(name="id_predmet", type="integer")
*/
private $predmet;
/**
* @var date $od
* @ORM\Column(name="od", type="date")
*/
private $od;
/**
* @var date $do
* @ORM\Column(name="do", type="date")
*/
private $do;
/**
* @var string $info
* @ORM\Column(name="info", type="string", length=120)
*/
private $info;
}
Predmet entity code:
/**
* @ORM\Table(name="predmeti")
* @ORM\Entity(repositoryClass="JP\AdminBundle\Repository\PredmetRepository")
*/
class Predmet
{
/**
* @var integer $id
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $sifra
* @ORM\Column(name="sifra", type="string", length=64)
*/
private $sifra;
/**
* @var boolean $vidljiv
* @ORM\Column(name="vidljiv", type="boolean")
*/
private $vidljiv;
}
Repository method:
$q = $this->createQueryBuilder('r')
->select('rzpp')
->where('rzpp.predmet = :predmet')
->from('JPAdminBundle:RokZaPrijavuProjekta', 'rzpp')
->leftJoin("rzpp.predmet", "p")
->setParameter('predmet', $predmet)
->getQuery();
Both getters and setters for all class members are defined properly.
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:
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?
UPDATE
- Added Predmet entity code...
- Added Repository method
Thanks a lot!
Regards,Jovan
Can you show Predmet entity code?
Or just try out this code:
// RokZaPrijavuProjekta
/**
* @ORM\ManyToOne(targetEntity="Predmet", inversedBy="rokzaprojects")
*/
protected $predmet;
//Predmet
/**
* @ORM\OneToMany(targetEntity="RokZaPrijavuProjekta", mappedBy="predmet")
*/
protected $rokzaprojects;
这篇关于教义类“.. \ ..”没有关联名称为“...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!