Zadejte hledaný výraz...

Doctrine 2 problémy s asociacemi a joinami

sajcah
verified
rating uzivatele
29. 1. 2014 14:37:45
Zdravím,
chtěl bych poprosit o pomoc.
Nejdříve napíšu o co se snažím:
Mám dvě tabulky employee a employee shop. Jedna podává informace o zaměstnanci a druhá je vazební a mezí id_employee a id_shop.
Co potřebuji? Potřebuji načíst zaměstnance podle ID dejme tomu a k němu načíst všechny id_shop.
Snažím se o to pomocí DQL dotazu:
$employee= Context::getContext()->entity_manager->createQuery('SELECT e,es FROM EmployeeEntity e JOIN e.employee_shop es WHERE id_employee = ?1')->setParameter(1,$this->id_employee)->getResult();
Definice entit vypada následovně:
/** @entity
* @table(name="mt_employee")
*/
class EmployeeEntity{
/**
* @id @column(type="integer")
* @generatedValue
*/
private $id_employee;
/** @column(length=100) */
private $login;
/** @column(length=300) */
private $password;
/** @column(length=50) */
private $name;
/** @column(length=50) */
private $surname;
/** @column(length=50) */
private $email;
/** @column(type="integer") */
private $remote_login;
/** @column(length=100) */
private $hash;
/**
* @oneToMany(targetEntity="EmployeeShopEntity", mappedBy="employee")
* @joinColumn(name="id_employee", referencedColumnName="id_employee")
*/
private $employe_shop;
public function getIdEmploeyee(){
return $this->id_employee;
}
public function getLogin(){
return $this->login;
}
public function getPassword(){
return $this->password;
}
public function getName(){
return $this->name;
}
public function getSurname(){
return $this->surname;
}
public function getEmail(){
return $this->email;
}
public function getRemoteLogin(){
return $this->remote_login;
}
public function getHash(){
return $this->hash;
}
public function getIdShop(){
return $this->employe_shop->getIdShop();
}
public function setLogin($login){
$this->login = $login;
}
public function setPassword($password){
$this->password = $password;
}
public function setName($name){
$this->name = $name;
}
public function setSurname($surname){
$this->surname = $surname;
}
public function setEmail($email){
$this->email = $email;
}
public function setRemoteLogin($login){
$this->remote_login = $login;
}
public function setHash($hash){
$this->hash = $hash;
}
}
/** @entity
* @table(name="mt_employee_shop")
*/
class EmployeeShopEntity{
/**
* @id @column(type="integer")
* @generatedValue
*/
private $id_employee_settings;
/** @column(type="integer") */
private $id_employee;
/** @column(type="integer") */
private $id_shop;
/**
* @manyToOne(targetEntity="EmployeeEntity", inversedBy="employe_shop")
* @joinColumn(name="id_employee", referencedColumnName="id_employee")
*/
private $employee;
public function getIdShop(){
return $this->id_shop;
}
//-----
public function setIdEmployee($id_employee){
$this->id_employee = $id_employee;
}
public function setIdShop($id_shop){
$this->id_shop = $id_shop;
}
}
Píše mě to chybu: Class EmployeeEntity has no association named employee_shop
Můžete mi prosím poradit jak by se data pro tento příklad měli správně tahat ?
Děkuji mockrát ! :)
29. 1. 2014 14:37:45
https://webtrh.cz/diskuse/doctrine-2-problemy-s-asociacemi-a-joinami/#reply991066
Pro odpověď se přihlašte.
Přihlásit