return $self->new_result($attrs)->insert;
}
+=head2 find_or_create(\%vals)
+
+ $class->find_or_create({ key => $val, ... });
+
+Searches for a record matching the search condition; if it doesn't find one,
+creates one and returns that instead.
+
+=cut
+
+sub find_or_create {
+ my $self = shift;
+ my $hash = ref $_[0] eq "HASH" ? shift: {@_};
+ my $exists = $self->find($hash);
+ return defined($exists) ? $exists : $self->create($hash);
+}
+
=head1 ATTRIBUTES
The resultset takes various attributes that modify its behavior.
sub count { shift->resultset_instance->count(@_); }
sub count_literal { shift->resultset_instance->count_literal(@_); }
sub find { shift->resultset_instance->find(@_); }
-sub create { shift->resultset_instance->create(@_); }
+sub create { shift->resultset_instance->create(@_); }
+sub find_or_create { shift->resultset_instance->find_or_create(@_); }
1;
$class->mk_classdata('table_instance' => $table);
}
-=head2 find_or_create
-
- $class->find_or_create({ key => $val, ... });
-
-Searches for a record matching the search condition; if it doesn't find one,
-creates one and returns that instead.
-
-=cut
-
-sub find_or_create {
- my $class = shift;
- my $hash = ref $_[0] eq "HASH" ? shift: {@_};
- my $exists = $class->find($hash);
- return defined($exists) ? $exists : $class->create($hash);
-}
-
=head2 has_column
if ($obj->has_column($col)) { ... }