<div dir="ltr">Hi, I have filed this the following bugs now:<div><br></div><div><a href="https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23272">https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23272</a> <- this one has patches<br></div><div><div><a href="https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23271">https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23271</a><br></div><br class="gmail-Apple-interchange-newline"></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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</div><div><br></div><div>sub search_with_branch_limits {</div>    my ( $self, $params, $attributes, $library_id ) = @_;<br><br><div>    my $or =<br>      $library_id<br>      ? {<br>        '-or' => [<br>            'authorised_values_branches.branchcode' => undef,<br>            'authorised_values_branches.branchcode' => $library_id,<br>        ]<br>      }<br>      : {};<br>    my $join = $library_id ? { join => 'authorised_values_branches' } : {};<br>    $attributes //= {};<br>    $attributes = { %$attributes, %$join };<br><div>    return $self->SUPER::search( { %$params, %$or, }, $attributes );</div><div>}</div><div><br></div><div>Note: I'd replace the table and column names for the configured ones.</div><div><br></div><div>Opinions?</div><div><br></div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div style="font-size:12.8px">Tomás Cohen Arazi</div><div style="font-size:12.8px">Theke Solutions (<a href="http://theke.io/" target="_blank">http://theke.io</a>)<br>✆ +54 9351 3513384<br>GPG: B2F3C15F</div></div></div></div></div></div></div></div>