GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Class::DBI::Plugin::DeepAbstractSearch(3) User Contributed Perl Documentation Class::DBI::Plugin::DeepAbstractSearch(3)

Class::DBI::Plugin::DeepAbstractSearch - deep_search_where() for Class::DBI

        use base 'Class::DBI';
        use Class::DBI::Plugin::DeepAbstractSearch;

        my @cds = Music::CD->deep_search_where(
                {
                        'artist.name' => $artist_name
                }
        );

This plugin provides a SQL::Abstract search method for Class::DBI. It is similar to Class::DBI::AbstractSearch, but allows you to search and sort by fields from joined tables.

Note: When searching and sorting by the fields of the current class only, it is more efficient to use Class::DBI::AbstractSearch.

        my @cds = Music::CD->deep_search_where(
                {
                        'artist.name' => $artist_name
                }
        );

This method will be exported into the calling class, and allows for searching of objects using SQL::Abstract format based on fields from the calling class as well as using fields in classes related through a (chain of) 'has_a' relationships to the calling class.

When specifying a field in a related class, you separate it with a period from the corresponding foreign key field in the primary class.

        package Music::Artist;
        use base 'Class::DBI';
        Music::Artist->table('artist');
        Music::Artist->columns(All => qw/artistid name/);
        Music::Artist->has_many(cds => 'Music::CD');

        package Music::CD;
        use base 'Class::DBI';
        Music::CD->table('cd');
        Music::CD->columns(All => qw/cdid artist title year/);
        Music::CD->has_many(tracks => 'Music::Track');
        Music::CD->has_a(artist => 'Music::Artist');

        package Music::Track;
        use base 'Class::DBI';
        Music::Track->table('track');
        Music::Track->columns(All => qw/trackid cd position title/); 

        ## Tracks on all CDs with the title "Greatest Hits"
        @tracks = Music::Track->deep_search_where(
                {
                        'cd.title' => "Greatest Hits"
                },
                {
                        sort_by => 'cd.title'
                }
        );

        ## Tracks on CDs by Willie Nelson, sorted by CD Title and Track Position
        @tracks = Music::Track->deep_search_where(
                {
                        'cd.artist.name' => "Willie Nelson"
                },
                {
                        sort_by => 'cd.title, position'
                }
        );

        ## First 3 Tracks on CDs, whose title contains "Outlaw", by Willie Nelson
        @tracks = Music::Track->deep_search_where(
                {
                        'cd.artist.name' => "Willie Nelson",
                        'cd.title' => { -like => '%Outlaw%' },
                        position => { '<=' => 3 }
                },
                {
                        sort_by => 'cd.title, position'
                }
        );

        my $num_cds = Music::CD->count_deep_search_where(
                {
                        'artist.name' => $artist_name
                }
        );

This method will be exported into the calling class, and allows for counting of objects using SQL::Abstract format based on fields from the calling class as well as using fields in classes related through a (chain of) 'has_a' relationships to the calling class.

    my ($what, $from, $where, $bind) = $class->get_deep_where($where, $attr);

This method will be exported into the calling class, and allows for retrieving SQL fragments used for creating queries. The parameters are the same as to deep_search_where.

Stepan Riha, "sriha@cpan.org"

Copyright (C) 2005, 2007, 2008 Stepan Riha. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Class::DBI, SQL::Abstract, Class::DBI::AbstractSearch
2008-01-18 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.