3
我有兩個實體user1和技能,其中一個用戶將有很多技能。Doctrine - ORM - 使用entityManager與關聯獲取所有數據
/** @Entity **/
class user1 {
/** @Id @Column(type="integer") @GeneratedValue **/
public $id;
/** @Column(type="string") **/
public $name;
/**
*
* @OneToMany(targetEntity="skills", mappedBy="uid")
*/
public $skillset;
}
/** @Entity **/
class skills {
/** @Id @Column(type="integer") @GeneratedValue **/
public $id;
/** @Column(type="string") **/
public $skill;
/**
* @ManyToOne(targetEntity="user1", inversedBy="skillset")
**/
public $uid;
}
但我想獲取使用的EntityManager和getrepository的所有記錄,如
$usr= $entityManager->getRepository("user1")->findAll();
但它給了我只從表「用戶1」的數據。而且我無法從與特定用戶相關聯的「技能」中獲取數據。
'uid'是'user1'表中'id'的'技能'表中的外鍵。
我檢查了一個用戶,它只能獲取與用戶相關的數據。我認爲我無法正確地進行繪圖或關聯。關於'ManyToMany',我嚴格需要'OneToMany'。你能給我舉一個例子來說明「OneToMany」嗎? –
儘管你沒有使用symfony,它的[Doctrine指南](http://symfony.com/doc/current/book/doctrine.html)可能對你有用。 – moonwave99