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 Returns the primary key(s) for a row. Can't be called as
32 $self->throw_exception( "Can't call id() as a class method" )
34 my @pk = $self->_ident_values;
35 return (wantarray ? @pk : $pk[0]);
40 return (map { $self->{_column_data}{$_} } $self->primary_columns);
45 Returns a unique id string identifying a row object by primary key.
46 Used by L<DBIx::Class::CDBICompat::LiveObjectIndex> and
47 L<DBIx::Class::ObjectCache>.
53 The default C<_create_ID> method used by this function orders the returned
54 values by the alphabetical order of the primary column names, B<unlike>
55 the L</id> method, which follows the same order in which columns were fed
56 to L<DBIx::Class::ResultSource/set_primary_key>.
64 $self->throw_exception( "Can't call ID() as a class method" )
66 return undef unless $self->in_storage;
67 return $self->_create_ID(map { $_ => $self->{_column_data}{$_} }
68 $self->primary_columns);
72 my ($self,%vals) = @_;
73 return undef unless 0 == grep { !defined } values %vals;
74 return join '|', ref $self || $self, $self->result_source->name,
75 map { $_ . '=' . $vals{$_} } sort keys %vals;
78 =head2 ident_condition
80 my $cond = $result_source->ident_condition();
82 my $cond = $result_source->ident_condition('alias');
84 Produces a condition hash to locate a row based on the primary key(s).
89 my ($self, $alias) = @_;
91 my $prefix = defined $alias ? $alias.'.' : '';
92 $cond{$prefix.$_} = $self->get_column($_) for $self->primary_columns;
100 Matt S. Trout <mst@shadowcatsystems.co.uk>
104 You may distribute this code under the same terms as Perl itself.