Hi all, IMO a ResultSet should not be instantiate in a pl script for some reasons (I already listed yesterday, nothing new :)) - should be unit tested - easier to maintain - easier to reuse But I don't think it's a big deal. I think someone (don't remember who) explained it is not a good idea to add too much changes to the ResultSet class. I tend to agree. In your example: $borrower->is_debarred Where do you instantiate $borrower? And where is defined is_debarred? I would write something like I have written for Koha::Acquisition::Order (bug 12830) package Koha::Borrower; use Koha::Schema; use base qw( Class::Accessor ); sub fetch { my ( $class, $borrowernumber ) = @_; my $borrower = Koha::Database->new->schema->resultset('Borrower')->find($borrowernumber, {result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); return $class->new( $borrower ); } sub is_debarred { my ( $self ) = @_; my $debarred_date = $self->{debarred}; return $debarred_date > $today; } in the pl file: my $borrower = Koha::Borrower->fetch( $borrowernumber ); The limitation in this implementation is that $borrower is not a DBIC object and we would like to get rid of HashRefInflator. Please comment this part of code and share yours! Cheers, Jonathan 2014-09-09 19:21 GMT+02:00 Kyle Hall <kyle.m.hall@gmail.com>:
As discussed in #koha, I think we are not using DBIC as well as we could. Right now we are only using it to replace hand written SQL queries. I would propose the following:
1) Allow find and simple searches in pl. 2) If a search is used more than once, it should be a ResultSet method 3) If a subroutine operates on a single table row, it should be a Result method 4) If a subroutine operates on a single table, it should be a ResultSet method 5) Any operation that works on tables linked by key constraints should take advantage of those DBIC relationships and also
In this way we can do things like: $borrower->is_debarred or $borrower->has_overdues or @borrowers = $borrower->guarantees()
Any search can be a method in the ResultSet such as $borrower->issue()->overdue_issues(); or my @records_with_holds = $schema->resultset('Biblio')->with_holds()
I think in the long run this will make or code far more readable, testable, and efficient.
What do you think?
Kyle
http://www.kylehall.info ByWater Solutions ( http://bywatersolutions.com ) Meadville Public Library ( http://www.meadvillelibrary.org ) Crawford County Federated Library System ( http://www.ccfls.org ) Mill Run Technology Solutions ( http://millruntech.com )
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/