X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=25e61d079e775716d78b6c814afefb10881be74d;hb=b7cf1606a66cca95e3540f803ffa66d223f23a40;hp=10b1cf64c75879842292912c00fbd28145380c11;hpb=f041c3f6e17bdacf8ad6b0da87342ef84e7db404;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 10b1cf64c..25e61d079 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -3093,7 +3093,7 @@ on the column first. sub ut_foreign_key { my( $self, $field, $table, $foreign ) = @_; - return '' if $no_check_foreign; + return $self->ut_number($field) if $no_check_foreign; qsearchs($table, { $foreign => $self->getfield($field) }) or return "Can't find ". $self->table. ".$field ". $self->getfield($field). " in $table.$foreign"; @@ -3133,12 +3133,12 @@ sub ut_agentnum_acl { if ( $self->$field() ) { - return "Access denied" + return 'Access denied to agent '. $self->$field() unless $curuser->agentnum($self->$field()); } else { - return "Access denied" + return 'Access denied to global' unless grep $curuser->access_right($_), @$null_acl; } @@ -3161,7 +3161,7 @@ sub fields { $table = $something->table; } else { $table = $something; - $something = "FS::$table"; + #$something = "FS::$table"; } return (real_fields($table)); } @@ -3336,6 +3336,22 @@ sub count { $self->scalar_sql($sql, @_); } +=item row_exists [ WHERE [, PLACEHOLDER ...] ] + +Convenience method for the common case of "SELECT 1 FROM table ... LIMIT 1" +with optional (but almost always needed) WHERE. + +=cut + +sub row_exists { + my($self, $where) = (shift, shift); + my $table = $self->table or die 'row_exists called on object of class '.ref($self); + my $sql = "SELECT 1 FROM $table"; + $sql .= " WHERE $where" if $where; + $sql .= " LIMIT 1"; + $self->scalar_sql($sql, @_); +} + =back =head1 SUBROUTINES