1 package DBIx::Class::ResultSource::View;
6 use DBIx::Class::ResultSet;
8 use base qw/DBIx::Class/;
9 __PACKAGE__->load_components(qw/ResultSource/);
10 __PACKAGE__->mk_group_accessors(
11 'simple' => qw(is_virtual view_definition)
16 DBIx::Class::ResultSource::View - ResultSource object representing a view
20 package MyDB::Schema::Year2000CDs;
22 use DBIx::Class::ResultSource::View;
24 __PACKAGE__->load_components('Core');
25 __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
27 __PACKAGE__->table('year2000cds');
28 __PACKAGE__->result_source_instance->is_virtual(1);
29 __PACKAGE__->result_source_instance->view_definition(
30 "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
35 View object that inherits from L<DBIx::Class::ResultSource>
37 This class extends ResultSource to add basic view support.
39 A view has a L</view_definition>, which contains an SQL query. The
40 query cannot have parameters. It may contain JOINs, sub selects and
41 any other SQL your database supports.
43 View definition SQL is deployed to your database on
44 L<DBIx::Class::Schema/deploy> unless you set L</is_virtual> to true.
46 Deploying the view does B<not> translate it between different database
47 syntaxes, so be careful what you write in your view SQL.
49 Virtual views (L</is_virtual> unset or false), are assumed to not
50 exist in your database as a real view. The L</view_definition> in this
51 case replaces the view name in a FROM clause in a subselect.
57 =item is_virtual set to true
59 $schema->resultset('Year2000CDs')->all();
61 SELECT cdid, artist, title FROM year2000cds me
63 =item is_virtual set to false
65 $schema->resultset('Year2000CDs')->all();
67 SELECT cdid, artist, title FROM
68 (SELECT cdid, artist, title FROM cd WHERE year ='2000') me
76 __PACKAGE__->result_source_instance->is_virtual(1);
78 Set to true for a virtual view, false or unset for a real
81 =head2 view_definition
83 __PACKAGE__->result_source_instance->view_definition(
84 "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
87 An SQL query for your view. Will not be translated across database
91 =head1 OVERRIDDEN METHODS
95 Returns the FROM entry for the table (i.e. the view name)
96 or the SQL as a subselect if this is a virtual view.
102 return \"(${\$self->view_definition})" if $self->is_virtual;
110 Matt S. Trout <mst@shadowcatsystems.co.uk>
112 With Contributions from:
114 Guillermo Roditi E<lt>groditi@cpan.orgE<gt>
116 Jess Robinson <castaway@desert-island.me.uk>
120 You may distribute this code under the same terms as Perl itself.