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
33 This method can also be used to refresh from storage, retrieving any
34 changes made since the row was last read from storage.
40 my $storage = $self->result_source->schema->storage;
41 $storage->reload_row($self);
47 Returns the primary key(s) for a row. Can't be called as
54 $self->throw_exception( "Can't call id() as a class method" )
56 my @pk = $self->_ident_values;
57 return (wantarray ? @pk : $pk[0]);
62 Returns a unique id string identifying a row object by primary key.
63 Used by L<DBIx::Class::CDBICompat::LiveObjectIndex> and
64 L<DBIx::Class::ObjectCache>.
70 $self->throw_exception( "Can't call ID() as a class method" )
72 return undef unless $self->in_storage;
73 return $self->_create_ID(map { $_ => $self->{_column_data}{$_} }
74 $self->primary_columns);
78 my ($self,%vals) = @_;
79 return undef unless 0 == grep { !defined } values %vals;
80 return join '|', ref $self || $self, $self->result_source->name,
81 map { $_ . '=' . $vals{$_} } sort keys %vals;
84 =head2 ident_condition
86 my $cond = $result_source->ident_condition();
88 my $cond = $result_source->ident_condition('alias');
90 Produces a condition hash to locate a row based on the primary key(s).
95 my ($self, $alias) = @_;
97 my $prefix = defined $alias ? $alias.'.' : '';
98 $cond{$prefix.$_} = $self->get_column($_) for $self->primary_columns;
106 Matt S. Trout <mst@shadowcatsystems.co.uk>
110 You may distribute this code under the same terms as Perl itself.