我用我的消息包实现了fosMessageBundle,但是如果我想发送一条新消息,请使用fos_message.composer,我得到了这个错误:
An exception occurred while executing 'INSERT INTO Message (body, created_at, threadId, sendId) VALUES (?, ?, ?, ?)' with params ["Test mesaju0131", "2013-12-23 12:15:48", 32, null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'sendId' cannot be null
我的问题是,为什么消息捆绑包没有设置发送 ID?
注意:我正在调试 setSender 数据。 每个数据似乎都可以。
代码:
$sender = $this->getUser();
$threadBuilder = $this->get('fos_message.composer')->newThread();
$threadBuilder->
addRecipient($clinicOwner)
->setSender($sender)
->setSubject($form['subject'])
->setBody($form['message']);
$sender = $this->get('fos_message.sender');
$sender->send($threadBuilder->getMessage());
问题
解决了!
message.orm.yml 中的 manyToOne.sender.joinColumn.name 写错了。
错:
manyToOne:
thread:
targetEntity: ATLMessageBundleEntityThread
inversedBy: messages
joinColumn:
name: threadId
referencedColumnName: id
sender:
targetEntity: ATLUserBundleEntityUser
joinColumn:
name: **threadId**
referencedColumnName: id
真:
manyToOne:
thread:
targetEntity: ATLMessageBundleEntityThread
inversedBy: messages
joinColumn:
name: threadId
referencedColumnName: id
sender:
targetEntity: ATLUserBundleEntityUser
joinColumn:
name: sendId
referencedColumnName: id