1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package My::Main::Result::Artist;
use base qw/ DBIx::Class::Core /;
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
__PACKAGE__->has_many( 'cds' => 'My::Main::Result::Cd' );
sub insert {
my ( $self, @args ) = @_;
$self->next::method(@args);
# $self->create_related ('cds', \%initial_cd_data );
print "42\n";
return $self;
}
1;
1
2
3
4
5
6
#
my $schema = My::Main->connect('...');
my @artists = ( ['M_Jackson'], ['N_Jones'], ['Depeche Mode'], ['U2'] );
$schema->populate('Artist', [ [qw/name/], @artists, ]);
#
QuoteIn void context, insert_bulk in DBIx::Class::Storage::DBI is used to insert the data, as this is a fast method. However, insert_bulk currently assumes that your datasets all contain the same type of values, using scalar references in a column in one row, and not in another will probably not work.
Otherwise, each set of data is inserted into the database using "create" in DBIx::Class::ResultSet, and a arrayref of the resulting row objects is returned.
my $newartist = $schema->resultset('Artist')->create({});