Php 理论2关系错误
我在将记录插入数据库时遇到问题。 我有三张名为 通知: id,id\u事件,事件\u id,已读取 评论: id、注释、接收者、发送者、已创建于 信息 id、主题、消息、接收者、发送者、已创建于 我想将notifications.id\u事件的注释和消息id与多对多关系相关联,如下所示Php 理论2关系错误,php,mysql,symfony,doctrine-orm,Php,Mysql,Symfony,Doctrine Orm,我在将记录插入数据库时遇到问题。 我有三张名为 通知: id,id\u事件,事件\u id,已读取 评论: id、注释、接收者、发送者、已创建于 信息 id、主题、消息、接收者、发送者、已创建于 我想将notifications.id\u事件的注释和消息id与多对多关系相关联,如下所示 oneToOne: comment: targetEntity: Comments joinColumn: name: id_event
oneToOne:
comment:
targetEntity: Comments
joinColumn:
name: id_event
referencedColumnName: id
message:
targetEntity: Messages
joinColumn:
name: id_event
referencedColumnName: id
当我尝试插入记录时,出现以下异常:
在上找到Doctrine\Common\Collections\ArrayCollection类型的实体
协会Privatmarket\BusinessBundle\Entity\Notifications消息,
但需要Privatmarket\BusinessBundle\Entity\Messages
我真的不知道该怎么办。也许我在选择方面犯了错误
插入代码为:
$comment = new Comments();
$comment->setSender(rand(1, 10));
$comment->setReceiver(rand(11, 20));
$comment->setComment("Lorem ipsum dolor sit amet {$i}, olor sit amet {$i}, psum dolor sit amet {$i}, olor sit amet {$i}, ");
$em->persist($comment);
$em->flush();
$notification = new Notifications();
$id = $comment->getId();
$notification->setComment($em->getRepository("PrivatmarketBusinessBundle:Comments")->find($id));
$notification->setEventId(2);
$em->persist($notification);
$em->flush();
$message = new Messages();
$message->setSender(rand(1, 10));
$message->setReceiver(rand(11, 20));
$message->setSubject("Lorem ipsu{$i}.");
$message->setMessage("Lorem ipsum dolor sit amet {$i}, olor sit amet {$i}, psum dolor sit amet {$i}, olor sit amet {$i}, Lorem ipsum dolor sit amet {$i}, olor sit amet {$i}, psum dolor sit amet {$i}, olor sit amet {$i}, ");
$em->persist($message);
$em->flush();
$notification = new Notifications();
$id = $message->getId();
$notification->setComment($em->getRepository("PrivatmarketBusinessBundle:Messages")->find($id));
$notification->setEventId(1);
$em->persist($notification);
$em->flush();
你得到的错误读起来像是改变
message:
targetEntity: Messages
joinColumn:
name: id_event
referencedColumnName: id
到
请注意,条令要求entityName为单数,因此如果它是一个集合,它会自动将getter和setter复数,可能这有点混淆了您可以粘贴插入代码吗?我已经添加了代码。我看不到您在通知中设置“消息”的任何代码行。你确定这是引起错误的代码吗?哇,这可能是一个非常聪明的答案,没有更多的细节。但是没有设置“消息”的代码被报告,所以,在给你“好答案点”之前,我想看看OP的代码:)
message:
targetEntity: Message
joinColumn:
name: id_event
referencedColumnName: id