1 package DBIx::Class::PK;
7 use base qw/DBIx::Class::Row/;
11 DBIx::Class::PK - Primary Key class
17 This class contains methods for handling primary keys and methods
26 return join(" AND ", map { "$_ = ?" } $class->primary_columns);
31 return (map { $self->{_column_data}{$_} } $self->primary_columns);
34 =head2 discard_changes
36 Re-selects the row from the database, losing any changes that had
43 delete $self->{_dirty_columns};
44 return unless $self->in_storage; # Don't reload if we aren't real!
45 my ($reload) = $self->find(map { $self->$_ } $self->primary_columns);
46 unless ($reload) { # If we got deleted in the mean-time
50 delete @{$self}{keys %$self};
51 @{$self}{keys %$reload} = values %$reload;
57 Returns the primary key(s) for a row. Can't be called as
64 $self->throw( "Can't call id() as a class method" ) unless ref $self;
65 my @pk = $self->_ident_values;
66 return (wantarray ? @pk : $pk[0]);
71 Returns a unique id string identifying a row object by primary key.
72 Used by L<DBIx::Class::CDBICompat::LiveObjectIndex> and
73 L<DBIx::Class::ObjectCache>.
79 $self->throw( "Can't call ID() as a class method" ) unless ref $self;
80 return undef unless $self->in_storage;
81 return $self->_create_ID(map { $_ => $self->{_column_data}{$_} } $self->primary_columns);
85 my ($class,%vals) = @_;
86 return undef unless 0 == grep { !defined } values %vals;
87 $class = ref $class || $class;
88 return join '|', $class, map { $_ . '=' . $vals{$_} } sort keys %vals;
92 my ($self, $alias) = @_;
94 $cond{(defined $alias ? "${alias}.$_" : $_)} = $self->get_column($_) for $self->primary_columns;
102 Matt S. Trout <mst@shadowcatsystems.co.uk>
106 You may distribute this code under the same terms as Perl itself.