[Koha-bugs] [Bug 22407] OMNIBUS: Use DBIC relations to fetch related object rather than searching for the object

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Jul 9 02:18:28 CEST 2020


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22407

David Cook <dcook at prosentient.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dcook at prosentient.com.au

--- Comment #13 from David Cook <dcook at prosentient.com.au> ---
Honest question:

Why do this:
sub guarantor {
    my $self = shift;
    my $guarantor_rs = $self->_result->guarantorid;
    return unless $guarantor_rs;
    return Koha::Patron->_new_from_dbic($gaurantor_rs);
}

Instead of this:
sub guarantor {
    my $self = shift;
    my $guarantor;
    my $guarantor_rs = $self->_result->guarantorid;
    if ($guarantor_rs){
        $guarantor = Koha::Patron->_new_from_dbic($gaurantor_rs);
    }
    return $guarantor;
}

I admit that the latter has 3 more lines than the former, but the latter is way
easier to read, easier to debug, and easier to add error-handling.

Actually, that latter should probably double-check the output of
Koha::Patron->_new_from_dbic() before returning.

I've noticed a lot of Koha code directly returning the output of a method call,
and it drives me crazy. We should do more data validation. It'll mean fewer
bugs and easier maintenance.

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.


More information about the Koha-bugs mailing list