1 package DBIx::Class::PK::Auto;
3 use base qw/Class::Data::Inheritable/;
9 DBIx::Class::PK::Auto - Automatic Primary Key class
15 This class overrides the insert method to get automatically
16 incremented primary keys.
18 You don't want to be using this directly - instead load the appropriate
19 one for your database, e.g. PK::Auto::SQLite
27 Overrides insert so that it will get the value of autoincremented
33 my ($self, @rest) = @_;
34 my $ret = $self->NEXT::ACTUAL::insert(@rest);
35 my ($pri, $too_many) =
36 (grep { $self->_primaries->{$_}{'auto_increment'} }
37 keys %{ $self->_primaries })
38 || (keys %{ $self->_primaries });
39 $self->throw( "More than one possible key found for auto-inc on ".ref $self )
41 unless (defined $self->get_column($pri)) {
42 $self->throw( "Can't auto-inc for $pri on ".ref $self.": no _last_insert_id method" )
43 unless $self->can('last_insert_id');
44 my $id = $self->last_insert_id;
45 $self->throw( "Can't get last insert id" ) unless $id;
46 $self->store_column($pri => $id);
53 Manually define the correct sequence for your table, to avoid the overhead
54 associated with looking up the sequence automatically.
58 __PACKAGE__->mk_classdata('sequence');
66 Matt S. Trout <mst@shadowcatsystems.co.uk>
70 You may distribute this code under the same terms as Perl itself.