- return map { $class->new($_) } @{$dbh->selectall_arrayref(
- # The categories table is small enough for
- # `SELECT *` to be harmless.
- "SELECT * FROM categories ORDER BY description",
- { Slice => {} },
- )};
+ # The categories table is small enough for
+ # `SELECT *` to be harmless.
+ my $query = "SELECT categories.* FROM categories";
+ $query .= qq{
+ LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode
+ WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL
+ } if $branch_limit;
+ $query .= " ORDER BY description";
+ return map { $class->new($_) } @{
+ $dbh->selectall_arrayref(
+ $query,
+ { Slice => {} },
+ $branch_limit ? $branch_limit : ()
+ )
+ };