Is DBIx::Class::Row::set_columns clever enough to update prefetched child rows?
I've tried it, and it doesn't seem to be. I'm probably expecting too much magic.
I did something like this:
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);
and got something like this:
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
It thinks 'invoice_lines' is just another column, rather than a relationship. The relationships are working properly when inserting into or reading from the database, so I haven't included all the gory details.
This feature isn't core although it is planned. Currently there is the DBIx::Class::ResultSet::RecursiveUpdate module that implements this.