projects
/
kivitendo-erp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
f6a762c
)
Manager: find_by_or_create, sichere Variante ein Objekt zu finden oder zu autovivifien.
author
Sven Schöling
<s.schoeling@linet-services.de>
Fri, 30 Dec 2011 16:27:58 +0000
(17:27 +0100)
committer
Sven Schöling
<s.schoeling@linet-services.de>
Fri, 30 Dec 2011 16:27:58 +0000
(17:27 +0100)
SL/DB/Helper/Manager.pm
patch
|
blob
|
history
diff --git
a/SL/DB/Helper/Manager.pm
b/SL/DB/Helper/Manager.pm
index
8ebc362
..
b4d66da
100644
(file)
--- a/
SL/DB/Helper/Manager.pm
+++ b/
SL/DB/Helper/Manager.pm
@@
-18,6
+18,14
@@
sub find_by {
return $class->get_all(query => [ @_ ], limit => 1)->[0];
}
+sub find_by_or_create {
+ my $class = shift;
+
+ my $found;
+ eval { $found = $class->find_by(@_); };
+ return defined $found ? $found : $class->object_class->new;
+}
+
sub get_first {
shift->get_all(
@_,