AutoUpdate, add_constructor, a toy set_sql emulator, object index stubs and destroy...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / Convenience.pm
1 package DBIx::Class::CDBICompat::Convenience;
2
3 use strict;
4 use warnings;
5
6 sub find_or_create {
7   my $class    = shift;
8   my $hash     = ref $_[0] eq "HASH" ? shift: {@_};
9   my ($exists) = $class->search($hash);
10   return defined($exists) ? $exists : $class->create($hash);
11 }
12
13 sub id {
14   my ($self) = @_;
15   die "Can't call id() as a class method" unless ref $self;
16   my @pk = $self->_ident_values;
17   return (wantarray ? @pk : $pk[0]);
18 }
19
20 #sub insert {
21 #  my $self = shift;
22 #  $self->NEXT::insert(@_);
23 #  my @pk = keys %{ $self->_primaries };
24 #  if ((@pk == 1) && (!$self->{_column_data}{$pk[0]})) {
25 #    $self->{_column_data}{$pk[0]} = $self->_get_dbh->last_insert_id;
26 #  }
27 #  return $self;
28 #}
29
30 sub retrieve_all {
31   my ($class) = @_;
32   return $class->search( { 1 => 1 } );
33 }
34
35 1;