I'm trying to join the Entities PhpbbTopics and PhpbbForums on the field forumId. These are PhpBB tables and therefore do not have a foreign key on a database level. However, when joining the two Entities using DQL I get the following exception:
[Semantical Error] line 0, col 78 near 'f': Error: Class
Project\MyBundle\Entity\PhpbbTopics has no association named forumId
The code that is being executed in my Controller is:
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT f.forumName
FROM ProjectMyBundle:PhpbbTopics t JOIN t.forumId f'
);
The two entites are:
**
* PhpbbTopics
*
* @ORM\Table(name="phpbb_topics", indexes={@ORM\Index(name="forum_id", columns={"forum_id"}), @ORM\Index(name="forum_id_type", columns={"forum_id", "topic_type"}), @ORM\Index(name="last_post_time", columns={"topic_last_post_time"}), @ORM\Index(name="topic_approved", columns={"topic_approved"}), @ORM\Index(name="forum_appr_last", columns={"forum_id", "topic_approved", "topic_last_post_id"}), @ORM\Index(name="fid_time_moved", columns={"forum_id", "topic_last_post_time", "topic_moved_id"})})
* @ORM\Entity
*/
class PhpbbTopics
{
/**
* @var \Project\MyBundle\Entity\PhpbbForums
*
* @ORM\ManyToOne(targetEntity="Project\MyBundle\Entity\PhpbbForums")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="forum_id", referencedColumnName="forum_id")
* })
*/
private $forumId;
}
And:
/**
* PhpbbForums
*
* @ORM\Table(name="phpbb_forums", indexes={@ORM\Index(name="left_right_id", columns={"left_id", "right_id"}), @ORM\Index(name="forum_lastpost_id", columns={"forum_last_post_id"})})
* @ORM\Entity
*/
class PhpbbForums
{
/**
* @var integer
*
* @ORM\Column(name="forum_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $forumId;
/**
* @var string
*
* @ORM\Column(name="forum_name", type="string", length=255, nullable=false)
*/
private $forumName;
}
Both of these entities have more fields than I have shown. These fields are not used in my query. Every field also has a getter and setter, which are not shown. If you feel the need to see more of the entities, please leave a comment.
I have tried the following solutions but they did not solve my issue:
- Doctrine Class “....” has no association named “…”
- Error: Class …\Entity.. has no association named
- Error: Class … has no field or association named
EDIT:
I found that the file PhpbbTopics.om.xml
at src\Project\MyBundle\Resources\config\doctrine
did not contain the relationship to PhpbbForums. I have replaced the line:
<field name="forumId" type="integer" column="forum_id" nullable="false"/>
With:
<many-to-one field="forumId" target-entity="PhpbbForums">
<join-columns>
<join-column name="forum_id" referenced-column-name="forum_id"/>
</join-columns>
</many-to-one>
This did not solve or change the issue.