1

使用 Zend Framework 1 和 Doctrine 1.2.4 构建的帮助/支持应用程序。

staff_id问题:在没有分配(支持人员)的情况下创建新的支持工单时,Doctrine 在staff表中插入空行,因为staff_id为 NULL,并且在表中找不到与值匹配idNULLstaff

新票已创建,请注意 NULL 值staff_id

INSERT INTO tickets (closable, emergency, survey_sent, brands_id, departments_id, categories_id, status_id, staff_id, subject, contacts_id, mask, initial_categories_id, last_opened, last_activity, created_at, updated_at) VALUES ('0', '1', '0', '1', '4', '6', '1', NULL, 'Cancellation Request', '5463', 'MQXB-39568', '6', '2012-06-14 03:15:49', '2012-06-14 03:15:49', '2012-06-14 03:15:49', '2012-06-14 03:15:49')

staff表中带有一些默认值的新行,这就是问题所在

INSERT INTO staff (enable_dst, last_page, external_links, replies_per_page, active) VALUES ('1', '0', '0', '10', '1')

出现野查询

DELETE FROM staff_index WHERE (id = '197')

现在ticket_posts(post = staff note)表用新插入的工单ID更新,表中新插入的空白行staffstaff_id这里应该是NULL)

UPDATE ticket_posts SET tickets_id = '12455', staff_id = '197', updated_at = '2012-06-14 03:15:49' WHERE id = '48113'

我通过将第二列(用户名)设置为非空来“解决”空行,但不是真正的解决方案。


有没有办法告诉Doctrine,这里无事可做,继续前进?


(^底线)

4

2 回答 2

0

http://doctrine.readthedocs.org/en/latest/en/manual/working-with-models.html#clearing-related-records

public function preSave()
{
    if (empty($this->staff_id))
        $this->clearRelated('Staff');
}
于 2012-07-09T20:55:40.600 回答
0

在持久化对象之前,您是否访问过 Ticket 实例上的 Staff 属性?这可能是 Doctrine 创建“空”记录的问题。

$ticket = new Ticket();
$ticket->Staff = NULL; # Doctrine will now add empty record.
$ticket->save();
于 2012-06-14T12:36:27.610 回答