View | Details | Raw Unified | Return to bug 24419
Collapse All | Expand All

(-)a/Koha/Schema/Result/Suggestion.pm (+12 lines)
Lines 443-448 __PACKAGE__->belongs_to( Link Here
443
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41
443
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41
444
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UsG/gxLa0HMMbcpbscV29Q
444
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UsG/gxLa0HMMbcpbscV29Q
445
445
446
__PACKAGE__->belongs_to(
447
  "suggestor",
448
  "Koha::Schema::Result::Borrower",
449
  { "foreign.borrowernumber" => "self.suggestedby" },
450
  {
451
    is_deferrable => 1,
452
    join_type     => "LEFT",
453
    on_delete     => "SET NULL",
454
    on_update     => "CASCADE",
455
  },
456
);
457
446
sub koha_objects_class {
458
sub koha_objects_class {
447
    'Koha::Suggestions';
459
    'Koha::Suggestions';
448
}
460
}
(-)a/Koha/Suggestion.pm (-2 / +22 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw(dt_from_string);
25
use Koha::DateUtils qw(dt_from_string);
26
use Koha::Patrons;
26
27
27
use base qw(Koha::Object);
28
use base qw(Koha::Object);
28
29
Lines 32-38 Koha::Suggestion - Koha Suggestion object class Link Here
32
33
33
=head1 API
34
=head1 API
34
35
35
=head2 Class Methods
36
=head2 Class methods
36
37
37
=cut
38
=cut
38
39
Lines 53-59 sub store { Link Here
53
    return $self->SUPER::store();
54
    return $self->SUPER::store();
54
}
55
}
55
56
56
=head3 type
57
=head3 suggestor
58
59
    my $patron = $suggestion->suggestor
60
61
Returns the I<Koha::Patron> for the suggestion generator. I<undef> is
62
returned if no suggestor is linked.
63
64
=cut
65
66
sub suggestor {
67
    my ($self) = @_;
68
69
    my $suggestor_rs = $self->_result->suggestor;
70
    return unless $suggestor_rs;
71
    return Koha::Patron->_new_from_dbic($suggestor_rs);
72
}
73
74
=head2 Internal methods
75
76
=head3 _type
57
77
58
=cut
78
=cut
59
79
(-)a/t/db_dependent/Koha/Suggestion.t (-1 / +50 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2020 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use Koha::Database;
25
use Koha::Suggestions;
26
27
use t::lib::TestBuilder;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'suggestor() tests' => sub {
33
34
    plan tests => 3;
35
36
    $schema->storage->txn_begin;
37
38
    my $patron     = $builder->build_object( { class => 'Koha::Patrons' } );
39
    my $suggestion = $builder->build_object(
40
        { class => 'Koha::Suggestions', value => { suggestedby => undef } } );
41
42
    is( $suggestion->suggestor, undef, 'Returns undef if no suggestor' );
43
    # Set a borrowernumber
44
    $suggestion->suggestedby($patron->borrowernumber)->store->discard_changes;
45
    my $suggestor = $suggestion->suggestor;
46
    is( ref($suggestor), 'Koha::Patron', 'Type is correct for suggestor' );
47
    is_deeply( $patron->unblessed, $suggestor->unblessed, 'It returns the right patron' );
48
49
    $schema->storage->txn_rollback;
50
};

Return to bug 24419