我有一个包含大量数据的数据库,我想在DQL中使用JOIN构建一个简单的查询,但我有一个“没有关联名称”的错误。 我在一个DB中有两个表,“main”和“users_main”,另一个DB中有一个表“
这是我的代码:
AdsMain.php:
/**
* @ORM\Column(name="user", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="Vt\KohanaBundle\Entity\AdsUsersMain")
* @ORM\JoinColumn(name="user", referencedColumnName="id")
*/
private $user;
AdsMainRepository.php
class AdsMainRepository extends EntityRepository {
public function findPremiumsCallCenter() {
$em = $this->getEntityManager();
$consulta = $em->createQuery(
'SELECT a.title , u.fullname
FROM
KohanaBundle:Main AS a
JOIN
a.user AS u'
);
$consulta->setMaxResults(20);
$lista = $consulta->getResult();
return $lista;
}
}
AdsUsersMain
class AdsUsersMain{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}
doctrine:
dbal:
default_connection: vt #default connection
connections:
vt:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name_vt%
user: %database_user_vt%
password: %database_password_vt%
charset: UTF8
kohana:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name_kohana%
user: %database_user_kohana%
password: %database_password_kohana%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
#auto_mapping: true
default_entity_manager: vt
entity_managers:
vt:
connection: vt
mappings:
VentaBundle : ~
UsuarioBundle : ~
kohana:
connection: kohana
mappings:
KohanaBundle : ~
当我调用函数findPremiumsCallCenter()时出现此错误:
[语义错误]第0行,第161行附近'AS u ':错误:类Vt \ KohanaBundle \ Entity \ AdsMain没有名为user的关联 500内部服务器错误 - QueryException
有人可以帮我吗?
答案 0 :(得分:0)