1Class::DBI::Plugin::DeeUpsAebrstCroancttrSiebaurtcehdC(l3Pa)esrsl::DDoBcIu:m:ePnltuagtiino:n:DeepAbstractSearch(3)
2
3
4

NAME

6       Class::DBI::Plugin::DeepAbstractSearch - deep_search_where() for
7       Class::DBI
8

SYNOPSIS

10               use base 'Class::DBI';
11               use Class::DBI::Plugin::DeepAbstractSearch;
12
13               my @cds = Music::CD->deep_search_where(
14                       {
15                               'artist.name' => $artist_name
16                       }
17               );
18

DESCRIPTION

20       This plugin provides a SQL::Abstract search method for Class::DBI.  It
21       is similar to Class::DBI::AbstractSearch, but allows you to search and
22       sort by fields from joined tables.
23
24       Note: When searching and sorting by the fields of the current class
25       only, it is more efficient to use Class::DBI::AbstractSearch.
26

METHODS

28   deep_search_where
29               my @cds = Music::CD->deep_search_where(
30                       {
31                               'artist.name' => $artist_name
32                       }
33               );
34
35       This method will be exported into the calling class, and allows for
36       searching of objects using SQL::Abstract format based on fields from
37       the calling class as well as using fields in classes related through a
38       (chain of) 'has_a' relationships to the calling class.
39
40       When specifying a field in a related class, you separate it with a
41       period from the corresponding foreign key field in the primary class.
42
43               package Music::Artist;
44               use base 'Class::DBI';
45               Music::Artist->table('artist');
46               Music::Artist->columns(All => qw/artistid name/);
47               Music::Artist->has_many(cds => 'Music::CD');
48
49               package Music::CD;
50               use base 'Class::DBI';
51               Music::CD->table('cd');
52               Music::CD->columns(All => qw/cdid artist title year/);
53               Music::CD->has_many(tracks => 'Music::Track');
54               Music::CD->has_a(artist => 'Music::Artist');
55
56               package Music::Track;
57               use base 'Class::DBI';
58               Music::Track->table('track');
59               Music::Track->columns(All => qw/trackid cd position title/);
60
61               ## Tracks on all CDs with the title "Greatest Hits"
62               @tracks = Music::Track->deep_search_where(
63                       {
64                               'cd.title' => "Greatest Hits"
65                       },
66                       {
67                               sort_by => 'cd.title'
68                       }
69               );
70
71               ## Tracks on CDs by Willie Nelson, sorted by CD Title and Track Position
72               @tracks = Music::Track->deep_search_where(
73                       {
74                               'cd.artist.name' => "Willie Nelson"
75                       },
76                       {
77                               sort_by => 'cd.title, position'
78                       }
79               );
80
81               ## First 3 Tracks on CDs, whose title contains "Outlaw", by Willie Nelson
82               @tracks = Music::Track->deep_search_where(
83                       {
84                               'cd.artist.name' => "Willie Nelson",
85                               'cd.title' => { -like => '%Outlaw%' },
86                               position => { '<=' => 3 }
87                       },
88                       {
89                               sort_by => 'cd.title, position'
90                       }
91               );
92
93   count_deep_search_where
94               my $num_cds = Music::CD->count_deep_search_where(
95                       {
96                               'artist.name' => $artist_name
97                       }
98               );
99
100       This method will be exported into the calling class, and allows for
101       counting of objects using SQL::Abstract format based on fields from the
102       calling class as well as using fields in classes related through a
103       (chain of) 'has_a' relationships to the calling class.
104
105   get_deep_where
106           my ($what, $from, $where, $bind) = $class->get_deep_where($where, $attr);
107
108       This method will be exported into the calling class, and allows for
109       retrieving SQL fragments used for creating queries.  The parameters are
110       the same as to deep_search_where.
111

AUTHOR

113       Stepan Riha, "sriha@cpan.org"
114
116       Copyright (C) 2005, 2007, 2008 Stepan Riha. All rights reserved.
117
118       This module is free software; you can redistribute it and/or modify it
119       under the same terms as Perl itself.
120

SEE ALSO

122       Class::DBI, SQL::Abstract, Class::DBI::AbstractSearch
123
124
125
126perl v5.36.0                      2023C-l0a1s-s2:0:DBI::Plugin::DeepAbstractSearch(3)
Impressum