Hi, I have filed this the following bugs now:
The idea is that we have Koha::Object::Limit::Library, currently only used in Koha::Patron::Attribute::Type, and we should use it as a reference.
But I have a question: I noticed in Koha::AuthorisedValues we overload ->search by allowing it to have a (surprise?) parameter: branchcode. I use the word 'surprise' because we've been leaning to the 'least surprise' principle and allowing to pass an attribute name that isn't in the model, seems like a surprise we would like to avoid.
I would like to propose we create an analogous Koha::Objects::Limit::Library class (notice the plural), implementing a specialized search method, with a name that clearly states the goal as discussed previously in the context of a bug I now don't remember :-D In the lines of
sub search_with_branch_limits {
my ( $self, $params, $attributes, $library_id ) = @_;
my $or =
$library_id
? {
'-or' => [
'authorised_values_branches.branchcode' => undef,
'authorised_values_branches.branchcode' => $library_id,
]
}
: {};
my $join = $library_id ? { join => 'authorised_values_branches' } : {};
$attributes //= {};
$attributes = { %$attributes, %$join };
return $self->SUPER::search( { %$params, %$or, }, $attributes );
}
Note: I'd replace the table and column names for the configured ones.
Opinions?