1 package SL::DB::Helper::Util;
5 use Rose::DB::Object::Util;
7 use parent qw(Exporter);
8 our @EXPORT_OK = qw(is_unique);
11 # Public functions not exported by default
15 my ($self, @columns) = @_;
17 my @filter = map { ($_ => $self->$_) } @columns;
18 if (Rose::DB::Object::Util::is_in_db($self)) {
19 push @filter, map { ("!${_}" => $self->$_ )} $self->meta->primary_key;
22 return !$self->_get_manager_class->get_first(where => [ and => \@filter ]);
35 SL::DB::Helper::Util - Helper functions for Rose::DB::Object instances
39 package SL::DB::AuthUser;
41 use SL::DB::Helper::Util;
45 if (!SL::DB::Helper::Util::is_unique($self, 'login')) {
46 push @errors, "Login not unique";
52 This is a collection of assorted helper and utility functions for
53 Rose::DB::Object instances that don't require full-blown mixin helpers
54 like L<SL::DB::ActsAsList>. The module does not export any function by
55 default, but all of the public ones can be requested in the usual
58 Each function can be called either as a fully qualified name with the
59 object instance as the first argument or (if the function is imported)
60 as an instance method on the object instance.
66 =item C<is_unique @columns>
68 Returns trueish if C<$self> is unique in its table regarding the
69 columns C<@columns>. What it does is look for existing records in the
70 database whose stored column values match C<$self>'s current values
71 for these columns. If C<$self> already exists in the database then
72 that row is not considered during the search.
82 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>