FosMessageBundle sendId不能为null

时间:2013-12-23 10:21:48

标签: php symfony message-bundle

我用我的消息包实现了fosMessageBundle,但是如果我想发送一条新消息,请使用fos_message.composer,我收到了这个错误:

    An exception occurred while executing 'INSERT INTO Message (body, created_at, threadId,   sendId) VALUES (?, ?, ?, ?)' with params ["Test mesaj\u0131", "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());

1 个答案:

答案 0 :(得分:0)

问题解决了!

message.orm.yml中的

manyToOne.sender.joinColumn.name是错误的。

错误:

manyToOne:
thread:
  targetEntity: ATL\MessageBundle\Entity\Thread
  inversedBy: messages
  joinColumn:
    name: threadId
    referencedColumnName: id
sender:
  targetEntity: ATL\UserBundle\Entity\User
  joinColumn:
    name: **threadId**
    referencedColumnName: id

是的:

manyToOne:
thread:
  targetEntity: ATL\MessageBundle\Entity\Thread
  inversedBy: messages
  joinColumn:
    name: threadId
    referencedColumnName: id
sender:
  targetEntity: ATL\UserBundle\Entity\User
  joinColumn:
    name: sendId
    referencedColumnName: id