1 package DBIx::Class::PK::Auto;
8 DBIx::Class::PK::Auto - Automatic Primary Key class
14 This class overrides the insert method to get automatically
15 incremented primary keys.
17 You don't want to be using this directly - instead load the appropriate
18 one for your database, e.g. PK::Auto::SQLite
26 Overrides insert so that it will get the value of autoincremented
32 my ($self, @rest) = @_;
33 my $ret = $self->NEXT::ACTUAL::insert(@rest);
34 my ($pri, $too_many) =
35 (grep { $self->_primaries->{$_}{'auto_increment'} }
36 keys %{ $self->_primaries })
37 || (keys %{ $self->_primaries });
38 $self->throw( "More than one possible key found for auto-inc on ".ref $self )
40 unless (defined $self->get_column($pri)) {
41 $self->throw( "Can't auto-inc for $pri on ".ref $self.": no _last_insert_id method" )
42 unless $self->can('last_insert_id');
43 my $id = $self->last_insert_id;
44 $self->throw( "Can't get last insert id" ) unless $id;
45 $self->store_column($pri => $id);
56 Matt S. Trout <perl-stuff@trout.me.uk>
60 You may distribute this code under the same terms as Perl itself.