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);
36 # if all primaries are already populated, skip auto-inc
38 map { $populated++ if $self->has_column($_) } $self->primary_columns;
39 return $ret if ( $populated == scalar $self->primary_columns );
41 my ($pri, $too_many) =
42 (grep { $self->column_info($_)->{'auto_increment'} }
43 $self->primary_columns)
44 || $self->primary_columns;
45 $self->throw( "More than one possible key found for auto-inc on ".ref $self )
47 unless (defined $self->get_column($pri)) {
48 $self->throw( "Can't auto-inc for $pri on ".ref $self.": no _last_insert_id method" )
49 unless $self->can('last_insert_id');
50 my $id = $self->last_insert_id;
51 $self->throw( "Can't get last insert id" ) unless $id;
52 $self->store_column($pri => $id);
59 Manually define the correct sequence for your table, to avoid the overhead
60 associated with looking up the sequence automatically.
64 __PACKAGE__->mk_classdata('sequence');
72 Matt S. Trout <mst@shadowcatsystems.co.uk>
76 You may distribute this code under the same terms as Perl itself.