Doctrine2:这些实体之间的关联有什么问题? [英] Doctrine2: What is wrong with the association between these entities?
本文介绍了Doctrine2:这些实体之间的关联有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过简单的示例来查看 Doctrine2 中的所有更改.
I am trying to work through simple examples to see all the changes in Doctrine2.
请查看以下实体片段:
VCat.php
namespace ApplicationModels;
/**
* @Entity
* @Table(name="v_cat")
*/
class VCat
{
/**
* @Id @Column(type="bigint")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @OneToMany(targetEntity="VScat", mappedBy="vCat") )
*/
private $vScats;
namespace ApplicationModels;
VScat.php
namespace ApplicationModels;
/**
* @Entity
* @Table(name="v_scat",indexes={@index(name="FK_v_scat",columns={"vcatid"})})
*/
class VScat
{
/**
* @Id @Column(type="bigint")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ManyToOne(targetEntity="VCat", inversedBy="vScats")
* @JoinColumn(name="vcatid", referencedColumnName="id")
*/
private $vCat;
vcatid
是表 v_scat 中的外键列
vcatid
is the Foreign Key column in table v_scat
这是我要运行的查询:
$categories = Zend_Registry::get('em')
-> createQuery('select c.name, sub.name as sub_name from ApplicationModelsVCat c JOIN c.VScat sub WHERE sub.active = 1 and c.active = 1 and c.id = sub.vcatid')
-> getResult();
这是错误:
(string:130) [Semantical Error] line 0, col 69 near 'sub WHERE sub.active': Error: Class ApplicationModelsVCat has no association named VScat
这似乎是对的,但我显然错过了一些东西.
It seems right, but I am obviously missing something.
UPDATE 现在我得到这个错误,它指的是 mysql 中的表列名.这是不正确的吗?我想我需要以某种方式告诉 Doctrine 这个属性属于数据库中的这个字段.
UPDATE Now I get this error, which refers to the table column name in mysql. Is that incorrect? I thought I needed to tell Doctrine somehow that this property belongs to this field in the DB.
Error: Class ApplicationModelsVScat has no field or association named vcatid
推荐答案
你需要引用的是VCat上的属性,而不是实体类型.
It's the property on VCat you need to reference not the entity type.
JOIN c.VScat sub
应该是:
JOIN c.vScats sub
这篇关于Doctrine2:这些实体之间的关联有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文