Lines 190-195
sub unblessed {
Link Here
|
190 |
return { $self->_result->get_columns }; |
190 |
return { $self->_result->get_columns }; |
191 |
} |
191 |
} |
192 |
|
192 |
|
|
|
193 |
=head3 $object->unblessed_all_relateds |
194 |
|
195 |
my $everything_into_one_hashref = $object->unblessed_all_relateds |
196 |
|
197 |
The unblessed method only retrieves column' values for the column of the object. |
198 |
In a *few* cases we want to retrieve the information of all the prefetched data. |
199 |
|
200 |
=cut |
201 |
|
202 |
sub unblessed_all_relateds { |
203 |
my ($self) = @_; |
204 |
|
205 |
my %data; |
206 |
my $related_resultsets = $self->_result->{related_resultsets} || {}; |
207 |
my $rs = $self; |
208 |
while ( $related_resultsets and %$related_resultsets ) { |
209 |
my @relations = keys %{ $related_resultsets }; |
210 |
if ( @relations ) { |
211 |
my $relation = $relations[0]; |
212 |
$rs = $rs->related_resultset($relation)->get_cache; |
213 |
$rs = $rs->[0]; # Does it makes sense to have several values here? |
214 |
my $object_class = Koha::Object::_get_object_class( $rs->result_class ); |
215 |
my $koha_object = $object_class->_new_from_dbic( $rs ); |
216 |
$related_resultsets = $rs->{related_resultsets}; |
217 |
%data = ( %data, %{ $koha_object->unblessed } ); |
218 |
} |
219 |
} |
220 |
%data = ( %data, %{ $self->unblessed } ); |
221 |
return \%data; |
222 |
} |
223 |
|
193 |
=head3 $object->_result(); |
224 |
=head3 $object->_result(); |
194 |
|
225 |
|
195 |
Returns the internal DBIC Row object |
226 |
Returns the internal DBIC Row object |
Lines 221-226
sub _columns {
Link Here
|
221 |
return $self->{_columns}; |
252 |
return $self->{_columns}; |
222 |
} |
253 |
} |
223 |
|
254 |
|
|
|
255 |
sub _get_object_class { |
256 |
my ( $type ) = @_; |
257 |
return unless $type; |
258 |
|
259 |
if( $type->can('koha_object_class') ) { |
260 |
return $type->koha_object_class; |
261 |
} |
262 |
$type =~ s|Schema::Result::||; |
263 |
return ${type}; |
264 |
} |
224 |
|
265 |
|
225 |
=head3 AUTOLOAD |
266 |
=head3 AUTOLOAD |
226 |
|
267 |
|
Lines 246-258
sub AUTOLOAD {
Link Here
|
246 |
} |
287 |
} |
247 |
} |
288 |
} |
248 |
|
289 |
|
249 |
my @known_methods = qw( is_changed id in_storage get_column ); |
290 |
my @known_methods = qw( is_changed id in_storage get_column related_resultset ); |
250 |
|
291 |
|
251 |
Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; |
292 |
Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; |
252 |
|
293 |
|
253 |
my $r = eval { $self->_result->$method(@_) }; |
294 |
my $r = eval { $self->_result->$method(@_) }; |
254 |
if ( $@ ) { |
295 |
if ( $@ ) { |
255 |
Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) ); |
296 |
Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) . " " . $@ ); |
256 |
} |
297 |
} |
257 |
return $r; |
298 |
return $r; |
258 |
} |
299 |
} |