DBIx::Class::Row::set_columns是否足够聪明以更新预取的子行?
我已经尝试过,而且似乎没有。我可能期待太多魔术。
我做了类似的事情:
my $data = {
id => 1,
date => '2015-06-27',
# etc.
invoice_lines => [{
id => 101,
# etc.
]},
};
my $rs = $schema->resultset('Invoice')->search(
{ 'me.id' => $id },
{ prefetch => 'invoice_lines' },
)->first;
$rs->set_columns($data);
得到这样的东西:
SELECT me.id, me.date, ..., invoice_lines.id, ... FROM invoices me LEFT
JOIN invoice_lines invoice_lines ON invoice_lines.invoice_id = me.id WHERE ( me.id = ? ) ORDER BY me.id: '1'
Mojo::Reactor::EV: Read failed: DBIx::Class::Row::get_column(): No such column 'invoice_lines' on MyProg::DB::Schema::Result::Invoice at /home
/chris/stuff/Invoices.pm line 289
它认为'invoice_lines'只是另一列,而不是关系。当插入或读取数据库时,这些关系正常工作,所以我没有包括所有的血腥细节。