$row_hash->{'changed_at'} = \'NOW()';
$row_hash->{'changed_by'} = $user_id;
- $c->log->debug( get_output_string( $K . "Buch-Row-Hash: ", $row_hash ) );
-
# Alles, was innerhalb einer Transaktion ablaufen soll ...
my $txn_code = sub {
- my $rs = $c->model('Schema::Buecher')->update_or_new( $row_hash, { 'key' => 'primary' },);
-
- $id = $rs->id();
- die $k . "Keine Id für das Buch gefunden.\n" unless $id;
- $c->log->debug( $K . "Verwende Buch-Id: " . $id );
+ my $rs;
- if ( $rs->in_storage() ) {
- $c->log->debug( $K . "Das Buch gibt es schon ..." );
- $rs->set_column( 'id' => \'LAST_INSERT_ID(`id`)' );
- $rs->update();
- }
+ if ( $row_hash->{'id'} ) {
+ $id = $row_hash->{'id'};
+ $c->log->debug( get_output_string( $K . "Aktualisiere Buch: ", $row_hash ) );
+ $rs = $c->model('Schema::Buecher')->search( { 'me.id' => $row_hash->{'id'} } )->update( $row_hash );
+ }
else {
- $c->log->debug( $K . "Neues Buch ..." );
- $rs->set_column( 'created_by' => $user_id );
- $rs->set_column( 'created_at' => \'NOW()' );
- $rs->insert();
+ $row_hash->{'created_at'} = \'NOW()';
+ $row_hash->{'created_by'} = $user_id;
+ $c->log->debug( get_output_string( $K . "Füge neues Buch ein: ", $row_hash ) );
+ $rs = $c->model('Schema::Buecher')->create($row_hash);
+ $id = $storage->last_insert_id();
}
- $id = $storage->last_insert_id();
+ die $k . "Keine Id für das Buch gefunden.\n" unless $id;
+ $c->log->debug( $K . "Verwende Buch-Id: " . $id );
$c->b_save_buch_autoren( $id, $book->{'autoren'} );
$c->b_save_buch_kategorien( $id, $book->{'kategorien'} );