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

(-)a/Koha/Schema/Result/AccountlineLink.pm (-25 / +25 lines)
Lines 43-49 foreign key to accountlines.accountlines_id Link Here
43
  is_nullable: 0
43
  is_nullable: 0
44
  size: 32
44
  size: 32
45
45
46
Type of linked entity: hold, old_hold, checkout, old_checkout, article_request, etc.
46
Type of linked entity: hold, checkout, article_request, etc.
47
47
48
=head2 linked_id
48
=head2 linked_id
49
49
Lines 143-151 This is a polymorphic relationship. Link Here
143
sub linked_object {
143
sub linked_object {
144
    my ($self) = @_;
144
    my ($self) = @_;
145
    
145
    
146
    # Special handling for holds - they can be in reserves OR old_reserves
147
    if ($self->link_type eq 'hold') {
148
        # Try current holds first
149
        my $hold = $self->result_source->schema->resultset('Reserve')->find({
150
            reserve_id => $self->linked_id
151
        });
152
        return $hold if $hold;
153
        
154
        # If not found in current holds, try old holds
155
        return $self->result_source->schema->resultset('OldReserve')->find({
156
            reserve_id => $self->linked_id
157
        });
158
    }
159
    
160
    # Handle other link types normally
146
    my $type_map = {
161
    my $type_map = {
147
        'hold'            => ['Reserve', 'reserve_id'],
148
        'old_hold'        => ['OldReserve', 'reserve_id'], 
149
        'checkout'        => ['Issue', 'issue_id'],
162
        'checkout'        => ['Issue', 'issue_id'],
150
        'old_checkout'    => ['OldIssue', 'issue_id'],
163
        'old_checkout'    => ['OldIssue', 'issue_id'],
151
        'article_request' => ['ArticleRequest', 'id'],
164
        'article_request' => ['ArticleRequest', 'id'],
Lines 159-196 sub linked_object { Link Here
159
    });
172
    });
160
}
173
}
161
174
162
=head2 linked_object_class
175
=head2 koha_objects_class
163
176
164
Returns the Koha::Object class name for the linked object
177
Missing POD for koha_objects_class.
165
178
166
=cut
179
=cut
167
180
168
sub linked_object_class {
181
sub koha_objects_class {
169
    my ($self) = @_;
182
    'Koha::Account::Links';
170
    
171
    my $class_map = {
172
        'hold'            => 'Koha::Hold',
173
        'old_hold'        => 'Koha::Old::Hold', 
174
        'checkout'        => 'Koha::Checkout',
175
        'old_checkout'    => 'Koha::Old::Checkout',
176
        'article_request' => 'Koha::ArticleRequest',
177
    };
178
    
179
    return $class_map->{$self->link_type};
180
}
183
}
181
184
182
=head2 validate_link_integrity
185
=head2 koha_object_class
183
186
184
Validates that the linked entity actually exists
187
Missing POD for koha_object_class.
185
188
186
=cut
189
=cut
187
190
188
sub validate_link_integrity {
191
sub koha_object_class {
189
    my ($self) = @_;
192
    'Koha::Account::Link';
190
    
191
    my $linked_object = $self->linked_object;
192
    return defined($linked_object) ? 1 : 0;
193
}
193
}
194
194
195
# You can replace this text with custom code or comments, and it will be preserved on regeneration
195
# You can replace this text with custom code or comments, and it will be preserved on regeneration
196
1;
196
1;
(-)a/Koha/Schema/Result/Reserve.pm (-1 / +13 lines)
Lines 588-591 __PACKAGE__->belongs_to( Link Here
588
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
588
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
589
);
589
);
590
590
591
__PACKAGE__->has_many(
592
  "accountline_links",
593
  "Koha::Schema::Result::AccountlineLink",
594
  sub {
595
    my ($args) = @_;
596
    return {
597
      "$args->{foreign_alias}.link_type" => 'hold',
598
      "$args->{foreign_alias}.linked_id" => { '=' => { -ident => "$args->{self_alias}.reserve_id" } },
599
    };
600
  },
601
  { cascade_copy => 0, cascade_delete => 0 },
602
);
603
591
1;
604
1;
592
- 

Return to bug 40808