未找到 2 个表与原则 2 之间的关联
我正在尝试练习 MySQL 表查询中的基本连接。阅读文档和< a href="http://groups.google.com/group/doctrine-user/browse_thread/thread/a9b63a7d57018da8?pli=1" rel="nofollow noreferrer">一些 问题 在 Stackoverflow 上,我仍然无法让它工作...
错误: 消息:[语义错误]第 0 行,第 74 列“o”附近:错误:类 Client_Model_Client 没有名为 Contact_Model_Contact 的关联
这里的代码是我的模型和我正在处理的查询:
模型客户端
<?php
/**
* @Table(name="client_clients")
* @Entity(repositoryClass="Client_Model_ClientRepository")
*/
class Client_Model_Client {
public function __construct()
{
$this->contacts = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @var integer $id
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @var string $name
* @Column(type="string")
*/
private $name;
/**
* @var string $address
* @Column(type="string")
*/
private $address;
/**
* @var string $comment
* @Column(type="string")
*/
private $comment;
/**
* @var integer $account_id
* @Column(type="integer")
*/
private $account_id;
/**
* @var integer $contact_id
* @Column(type="integer")
*/
private $contact_id;
/**
* @var string $created_at
* @Column(type="string")
*/
private $created_at;
/**
* @var contact_data $contact_data
* @Column(name="contact_data", type="integer", nullable=false)
* @OneToMany(targetEntity="Contact_Model_Contact", mappedBy="contact_data")
* @JoinColumn(name="contact_id", referencedColumnName="id")
*/
private $contact_data;
... (getters and setters)
模型联系人
<?php
/**
* @Table(name="contact_contacts")
* @Entity(repositoryClass="Contact_Model_ContactRepository")
*/
class Contact_Model_Contact {
/**
* @var integer $id
* @Id @Column(type="integer")
* @GeneratedValue
* @ManyToOne(targetEntity="Client_Model_Client", mappedBy="contact_data")
*/
private $id;
/**
* @var string $name
* @Column(type="string")
*/
private $name;
/**
* @var string $email
* @Column(type="string")
*/
private $email;
/**
* @var string $phone
* @Column(type="string")
*/
private $phone;
/**
* @var integer $address
* @Column(type="string")
*/
private $address;
/**
* @var string $comment
* @Column(type="string")
*/
private $comment;
/**
* @var string $created_at
* @Column(type="string")
*/
private $created_at;
/**
* @var integer $contact_id
* @Column(type="string")
*/
private $contact_id;
查询
$qb = $this->_em->createQueryBuilder()
->select('i, o')
->from('Client_Model_Client', 'i')
->join('i.Contact_Model_Contact', 'o');
$query = $qb->getQuery();
$roles = $query->getResult();
Zend_Debug::dump($roles); die;
我做错了什么? 应该如何运作?
I'm trying to workout a basic join in a query for MySQL-tables. After reading the documentation and some questions on Stackoverflow, I still can't get it to work ...
The error:
Message: [Semantical Error] line 0, col 74 near 'o': Error: Class Client_Model_Client has no association named Contact_Model_Contact
The code here, are my models and the query I'm working on:
Model client
<?php
/**
* @Table(name="client_clients")
* @Entity(repositoryClass="Client_Model_ClientRepository")
*/
class Client_Model_Client {
public function __construct()
{
$this->contacts = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @var integer $id
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @var string $name
* @Column(type="string")
*/
private $name;
/**
* @var string $address
* @Column(type="string")
*/
private $address;
/**
* @var string $comment
* @Column(type="string")
*/
private $comment;
/**
* @var integer $account_id
* @Column(type="integer")
*/
private $account_id;
/**
* @var integer $contact_id
* @Column(type="integer")
*/
private $contact_id;
/**
* @var string $created_at
* @Column(type="string")
*/
private $created_at;
/**
* @var contact_data $contact_data
* @Column(name="contact_data", type="integer", nullable=false)
* @OneToMany(targetEntity="Contact_Model_Contact", mappedBy="contact_data")
* @JoinColumn(name="contact_id", referencedColumnName="id")
*/
private $contact_data;
... (getters and setters)
Model Contact
<?php
/**
* @Table(name="contact_contacts")
* @Entity(repositoryClass="Contact_Model_ContactRepository")
*/
class Contact_Model_Contact {
/**
* @var integer $id
* @Id @Column(type="integer")
* @GeneratedValue
* @ManyToOne(targetEntity="Client_Model_Client", mappedBy="contact_data")
*/
private $id;
/**
* @var string $name
* @Column(type="string")
*/
private $name;
/**
* @var string $email
* @Column(type="string")
*/
private $email;
/**
* @var string $phone
* @Column(type="string")
*/
private $phone;
/**
* @var integer $address
* @Column(type="string")
*/
private $address;
/**
* @var string $comment
* @Column(type="string")
*/
private $comment;
/**
* @var string $created_at
* @Column(type="string")
*/
private $created_at;
/**
* @var integer $contact_id
* @Column(type="string")
*/
private $contact_id;
The query
$qb = $this->_em->createQueryBuilder()
->select('i, o')
->from('Client_Model_Client', 'i')
->join('i.Contact_Model_Contact', 'o');
$query = $qb->getQuery();
$roles = $query->getResult();
Zend_Debug::dump($roles); die;
What am I doing wrong?
How should it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该这样做:
You should be doing this: