1package DBIx::Class::Helper::ResultSet::Util;
2$DBIx::Class::Helper::ResultSet::Util::VERSION = '2.036000';
3use strict;
4use warnings;
5
6# ABSTRACT: Helper utilities for DBIx::Class ResultSets
7
8use Sub::Exporter::Progressive -setup => {
9   exports => [
10      qw( correlate ),
11   ],
12};
13
14
15my $recent_dbic;
16sub correlate {
17   my ($rs, $rel) = @_;
18
19   my $source = $rs->result_source;
20
21   $recent_dbic = $source->can('resolve_relationship_condition') ? 1 : 0
22      if not defined $recent_dbic;
23
24   return $source->related_source($rel)->resultset
25      ->search(
26
27         ($recent_dbic
28
29            ? $source->resolve_relationship_condition(
30               rel_name => $rel,
31               foreign_alias => "${rel}_alias",
32               self_alias => $rs->current_source_alias,
33            )->{condition}
34
35            : scalar $source->_resolve_condition(
36               $source->relationship_info($rel)->{cond},
37               "${rel}_alias",
38               $rs->current_source_alias,
39               $rel
40            )
41
42         ),
43
44         { alias => "${rel}_alias" }
45      );
46}
47
481;
49
50__END__
51
52=pod
53
54=head1 NAME
55
56DBIx::Class::Helper::ResultSet::Util - Helper utilities for DBIx::Class ResultSets
57
58=head1 DESCRIPTION
59
60These functions will slowly become the core implementations of many existing
61components.  The reason for this is that often you are not able to or unwilling
62to add a component to an object, as adding the component fundamentally changes
63the object.  If instead you merely act on the object with a subroutine you are
64not committing as seriously.
65
66=head1 EXPORTS
67
68=head2 correlate
69
70 correlate($author_rs, 'books')
71
72This function allows you to correlate a resultset with one of it's
73relationships.  It takes the ResultSet and relationship name as arguments.  See
74L<DBIx::Class::Helper::ResultSet::CorrelateRelationship/SYNOPSIS> for an in
75depth example.
76
77=head1 AUTHOR
78
79Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
80
81=head1 COPYRIGHT AND LICENSE
82
83This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
84
85This is free software; you can redistribute it and/or modify it under
86the same terms as the Perl 5 programming language system itself.
87
88=cut
89