1 package DBIx::Class::PK;
6 use base qw/DBIx::Class::Row/;
10 DBIx::Class::PK - Primary Key class
16 This class contains methods for handling primary keys and methods
25 return (map { $self->{_column_data}{$_} } $self->primary_columns);
28 =head2 discard_changes
30 Re-selects the row from the database, losing any changes that had
37 delete $self->{_dirty_columns};
38 return unless $self->in_storage; # Don't reload if we aren't real!
39 my ($reload) = $self->result_source->resultset->find
40 (map { $self->$_ } $self->primary_columns);
41 unless ($reload) { # If we got deleted in the mean-time
45 delete @{$self}{keys %$self};
46 @{$self}{keys %$reload} = values %$reload;
52 Returns the primary key(s) for a row. Can't be called as
59 $self->throw_exception( "Can't call id() as a class method" )
61 my @pk = $self->_ident_values;
62 return (wantarray ? @pk : $pk[0]);
67 Returns a unique id string identifying a row object by primary key.
68 Used by L<DBIx::Class::CDBICompat::LiveObjectIndex> and
69 L<DBIx::Class::ObjectCache>.
75 $self->throw_exception( "Can't call ID() as a class method" )
77 return undef unless $self->in_storage;
78 return $self->_create_ID(map { $_ => $self->{_column_data}{$_} }
79 $self->primary_columns);
83 my ($self,%vals) = @_;
84 return undef unless 0 == grep { !defined } values %vals;
85 return join '|', ref $self || $self, $self->result_source->name,
86 map { $_ . '=' . $vals{$_} } sort keys %vals;
89 =head2 ident_condition
91 my $cond = $result_source->ident_condition();
93 my $cond = $result_source->ident_condition('alias');
95 Produces a condition hash to locate a row based on the primary key(s).
100 my ($self, $alias) = @_;
102 $cond{(defined $alias ? "${alias}.$_" : $_)} = $self->get_column($_)
103 for $self->primary_columns;
111 Matt S. Trout <mst@shadowcatsystems.co.uk>
115 You may distribute this code under the same terms as Perl itself.