1 package DBIx::Class::ResultSource;
6 use DBIx::Class::ResultSet;
7 use DBIx::Class::ResultSourceHandle;
8 use Carp::Clan qw/^DBIx::Class/;
11 use base qw/DBIx::Class/;
13 __PACKAGE__->mk_group_accessors('simple' => qw/_ordered_columns
14 _columns _primaries _unique_constraints name resultset_attributes
15 schema from _relationships column_info_from_storage source_info
18 __PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class
23 DBIx::Class::ResultSource - Result source object
29 A ResultSource is a component of a schema from which results can be directly
30 retrieved, most usually a table (see L<DBIx::Class::ResultSource::Table>)
40 $class->new({attribute_name => value});
42 Creates a new ResultSource object. Not normally called directly by end users.
47 my ($class, $attrs) = @_;
48 $class = ref $class if ref $class;
50 my $new = bless { %{$attrs || {}} }, $class;
51 $new->{resultset_class} ||= 'DBIx::Class::ResultSet';
52 $new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} };
53 $new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}];
54 $new->{_columns} = { %{$new->{_columns}||{}} };
55 $new->{_relationships} = { %{$new->{_relationships}||{}} };
56 $new->{name} ||= "!!NAME NOT SET!!";
57 $new->{_columns_info_loaded} ||= 0;
65 Stores a hashref of per-source metadata. No specific key names
66 have yet been standardized, the examples below are purely hypothetical
67 and don't actually accomplish anything on their own:
69 __PACKAGE__->source_info({
70 "_tablespace" => 'fast_disk_array_3',
71 "_engine" => 'InnoDB',
82 Returns true if the resultsource is a virtual result source. This stub
83 method returns false by default, see L<DBIx::Class::ResultSource::View>
88 $table->add_columns(qw/col1 col2 col3/);
90 $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
92 Adds columns to the result source. If supplied key => hashref pairs, uses
93 the hashref as the column_info for that column. Repeated calls of this
94 method will add more columns, not replace them.
96 The column names given will be created as accessor methods on your
97 L<DBIx::Class::Row> objects, you can change the name of the accessor
98 by supplying an L</accessor> in the column_info hash.
100 The contents of the column_info are not set in stone. The following
101 keys are currently recognised/used by DBIx::Class:
107 Use this to set the name of the accessor method for this column. If unset,
108 the name of the column will be used.
112 This contains the column type. It is automatically filled by the
113 L<SQL::Translator::Producer::DBIx::Class::File> producer, and the
114 L<DBIx::Class::Schema::Loader> module. If you do not enter a
115 data_type, DBIx::Class will attempt to retrieve it from the
116 database for you, using L<DBI>'s column_info method. The values of this
117 key are typically upper-cased.
119 Currently there is no standard set of values for the data_type. Use
120 whatever your database supports.
124 The length of your column, if it is a column type that can have a size
125 restriction. This is currently only used by L<DBIx::Class::Schema/deploy>.
129 Set this to a true value for a columns that is allowed to contain
130 NULL values. This is currently only used by L<DBIx::Class::Schema/deploy>.
132 =item is_auto_increment
134 Set this to a true value for a column whose value is somehow
135 automatically set. This is used to determine which columns to empty
136 when cloning objects using C<copy>. It is also used by
137 L<DBIx::Class::Schema/deploy>.
141 Set this to a true value for a column that contains a key from a
142 foreign table. This is currently only used by
143 L<DBIx::Class::Schema/deploy>.
147 Set this to the default value which will be inserted into a column
148 by the database. Can contain either a value or a function. This is
149 currently only used by L<DBIx::Class::Schema/deploy>.
153 Set this on a primary key column to the name of the sequence used to
154 generate a new key value. If not specified, L<DBIx::Class::PK::Auto>
155 will attempt to retrieve the name of the sequence from the database
160 Set this to a true value for a column whose value is retrieved
161 automatically from an oracle sequence. If you do not use an oracle
162 trigger to get the nextval, you have to set sequence as well.
166 This is used by L<DBIx::Class::Schema/deploy> and L<SQL::Translator>
167 to add extra non-generic data to the column. For example: C<< extra
168 => { unsigned => 1} >> is used by the MySQL producer to set an integer
169 column to unsigned. For more details, see
170 L<SQL::Translator::Producer::MySQL>.
176 $table->add_column('col' => \%info?);
178 Convenience alias to add_columns.
183 my ($self, @cols) = @_;
184 $self->_ordered_columns(\@cols) unless $self->_ordered_columns;
187 my $columns = $self->_columns;
188 while (my $col = shift @cols) {
189 # If next entry is { ... } use that for the column info, if not
190 # use an empty hashref
191 my $column_info = ref $cols[0] ? shift(@cols) : {};
192 push(@added, $col) unless exists $columns->{$col};
193 $columns->{$col} = $column_info;
195 push @{ $self->_ordered_columns }, @added;
199 sub add_column { shift->add_columns(@_); } # DO NOT CHANGE THIS TO GLOB
203 if ($obj->has_column($col)) { ... }
205 Returns true if the source has a column of this name, false otherwise.
210 my ($self, $column) = @_;
211 return exists $self->_columns->{$column};
216 my $info = $obj->column_info($col);
218 Returns the column metadata hashref for a column. See the description
219 of add_column for information on the contents of the hashref.
224 my ($self, $column) = @_;
225 $self->throw_exception("No such column $column")
226 unless exists $self->_columns->{$column};
227 #warn $self->{_columns_info_loaded}, "\n";
228 if ( ! $self->_columns->{$column}{data_type}
229 and $self->column_info_from_storage
230 and ! $self->{_columns_info_loaded}
231 and $self->schema and $self->storage )
233 $self->{_columns_info_loaded}++;
236 # eval for the case of storage without table
237 eval { $info = $self->storage->columns_info_for( $self->from ) };
239 for my $realcol ( keys %{$info} ) {
240 $lc_info->{lc $realcol} = $info->{$realcol};
242 foreach my $col ( keys %{$self->_columns} ) {
243 $self->_columns->{$col} = {
244 %{ $self->_columns->{$col} },
245 %{ $info->{$col} || $lc_info->{lc $col} || {} }
250 return $self->_columns->{$column};
253 =head2 column_info_from_storage
255 Enables the on-demand automatic loading of the above column
256 metadata from storage as neccesary. This is *deprecated*, and
257 should not be used. It will be removed before 1.0.
259 __PACKAGE__->column_info_from_storage(1);
263 my @column_names = $obj->columns;
265 Returns all column names in the order they were declared to add_columns.
271 $self->throw_exception(
272 "columns() is a read-only accessor, did you mean add_columns()?"
274 return @{$self->{_ordered_columns}||[]};
277 =head2 remove_columns
279 $table->remove_columns(qw/col1 col2 col3/);
281 Removes columns from the result source.
285 $table->remove_column('col');
287 Convenience alias to remove_columns.
292 my ($self, @cols) = @_;
294 return unless $self->_ordered_columns;
296 my $columns = $self->_columns;
299 foreach my $col (@{$self->_ordered_columns}) {
300 push @remaining, $col unless grep(/$col/, @cols);
304 delete $columns->{$_};
307 $self->_ordered_columns(\@remaining);
310 sub remove_column { shift->remove_columns(@_); } # DO NOT CHANGE THIS TO GLOB
312 =head2 set_primary_key
316 =item Arguments: @cols
320 Defines one or more columns as primary key for this source. Should be
321 called after C<add_columns>.
323 Additionally, defines a unique constraint named C<primary>.
325 The primary key columns are used by L<DBIx::Class::PK::Auto> to
326 retrieve automatically created values from the database.
330 sub set_primary_key {
331 my ($self, @cols) = @_;
332 # check if primary key columns are valid columns
333 foreach my $col (@cols) {
334 $self->throw_exception("No such column $col on table " . $self->name)
335 unless $self->has_column($col);
337 $self->_primaries(\@cols);
339 $self->add_unique_constraint(primary => \@cols);
342 =head2 primary_columns
344 Read-only accessor which returns the list of primary keys.
348 sub primary_columns {
349 return @{shift->_primaries||[]};
352 =head2 add_unique_constraint
354 Declare a unique constraint on this source. Call once for each unique
357 # For UNIQUE (column1, column2)
358 __PACKAGE__->add_unique_constraint(
359 constraint_name => [ qw/column1 column2/ ],
362 Alternatively, you can specify only the columns:
364 __PACKAGE__->add_unique_constraint([ qw/column1 column2/ ]);
366 This will result in a unique constraint named C<table_column1_column2>, where
367 C<table> is replaced with the table name.
369 Unique constraints are used, for example, when you call
370 L<DBIx::Class::ResultSet/find>. Only columns in the constraint are searched.
374 sub add_unique_constraint {
379 $name ||= $self->name_unique_constraint($cols);
381 foreach my $col (@$cols) {
382 $self->throw_exception("No such column $col on table " . $self->name)
383 unless $self->has_column($col);
386 my %unique_constraints = $self->unique_constraints;
387 $unique_constraints{$name} = $cols;
388 $self->_unique_constraints(\%unique_constraints);
391 =head2 name_unique_constraint
393 Return a name for a unique constraint containing the specified columns. These
394 names consist of the table name and each column name, separated by underscores.
396 For example, a constraint on a table named C<cd> containing the columns
397 C<artist> and C<title> would result in a constraint name of C<cd_artist_title>.
401 sub name_unique_constraint {
402 my ($self, $cols) = @_;
404 return join '_', $self->name, @$cols;
407 =head2 unique_constraints
409 Read-only accessor which returns the list of unique constraints on this source.
413 sub unique_constraints {
414 return %{shift->_unique_constraints||{}};
417 =head2 unique_constraint_names
419 Returns the list of unique constraint names defined on this source.
423 sub unique_constraint_names {
426 my %unique_constraints = $self->unique_constraints;
428 return keys %unique_constraints;
431 =head2 unique_constraint_columns
433 Returns the list of columns that make up the specified unique constraint.
437 sub unique_constraint_columns {
438 my ($self, $constraint_name) = @_;
440 my %unique_constraints = $self->unique_constraints;
442 $self->throw_exception(
443 "Unknown unique constraint $constraint_name on '" . $self->name . "'"
444 ) unless exists $unique_constraints{$constraint_name};
446 return @{ $unique_constraints{$constraint_name} };
451 Returns an expression of the source to be supplied to storage to specify
452 retrieval from this source. In the case of a database, the required FROM
457 Returns the L<DBIx::Class::Schema> object that this result source
462 Returns the storage handle for the current schema.
464 See also: L<DBIx::Class::Storage>
468 sub storage { shift->schema->storage; }
470 =head2 add_relationship
472 $source->add_relationship('relname', 'related_source', $cond, $attrs);
474 The relationship name can be arbitrary, but must be unique for each
475 relationship attached to this result source. 'related_source' should
476 be the name with which the related result source was registered with
477 the current schema. For example:
479 $schema->source('Book')->add_relationship('reviews', 'Review', {
480 'foreign.book_id' => 'self.id',
483 The condition C<$cond> needs to be an L<SQL::Abstract>-style
484 representation of the join between the tables. For example, if you're
485 creating a rel from Author to Book,
487 { 'foreign.author_id' => 'self.id' }
489 will result in the JOIN clause
491 author me JOIN book foreign ON foreign.author_id = me.id
493 You can specify as many foreign => self mappings as necessary.
495 Valid attributes are as follows:
501 Explicitly specifies the type of join to use in the relationship. Any
502 SQL join type is valid, e.g. C<LEFT> or C<RIGHT>. It will be placed in
503 the SQL command immediately before C<JOIN>.
507 An arrayref containing a list of accessors in the foreign class to proxy in
508 the main class. If, for example, you do the following:
510 CD->might_have(liner_notes => 'LinerNotes', undef, {
511 proxy => [ qw/notes/ ],
514 Then, assuming LinerNotes has an accessor named notes, you can do:
516 my $cd = CD->find(1);
517 # set notes -- LinerNotes object is created if it doesn't exist
518 $cd->notes('Notes go here');
522 Specifies the type of accessor that should be created for the
523 relationship. Valid values are C<single> (for when there is only a single
524 related object), C<multi> (when there can be many), and C<filter> (for
525 when there is a single related object, but you also want the relationship
526 accessor to double as a column accessor). For C<multi> accessors, an
527 add_to_* method is also created, which calls C<create_related> for the
534 sub add_relationship {
535 my ($self, $rel, $f_source_name, $cond, $attrs) = @_;
536 $self->throw_exception("Can't create relationship without join condition")
540 # Check foreign and self are right in cond
541 if ( (ref $cond ||'') eq 'HASH') {
543 $self->throw_exception("Keys of condition should be of form 'foreign.col', not '$_'")
544 if /\./ && !/^foreign\./;
548 my %rels = %{ $self->_relationships };
549 $rels{$rel} = { class => $f_source_name,
550 source => $f_source_name,
553 $self->_relationships(\%rels);
557 # XXX disabled. doesn't work properly currently. skip in tests.
559 my $f_source = $self->schema->source($f_source_name);
561 $self->ensure_class_loaded($f_source_name);
562 $f_source = $f_source_name->result_source;
563 #my $s_class = ref($self->schema);
564 #$f_source_name =~ m/^${s_class}::(.*)$/;
565 #$self->schema->register_class(($1 || $f_source_name), $f_source_name);
566 #$f_source = $self->schema->source($f_source_name);
568 return unless $f_source; # Can't test rel without f_source
570 eval { $self->resolve_join($rel, 'me') };
572 if ($@) { # If the resolve failed, back out and re-throw the error
573 delete $rels{$rel}; #
574 $self->_relationships(\%rels);
575 $self->throw_exception("Error creating relationship $rel: $@");
582 Returns all relationship names for this source.
587 return keys %{shift->_relationships};
590 =head2 relationship_info
594 =item Arguments: $relname
598 Returns a hash of relationship information for the specified relationship
603 sub relationship_info {
604 my ($self, $rel) = @_;
605 return $self->_relationships->{$rel};
608 =head2 has_relationship
612 =item Arguments: $rel
616 Returns true if the source has a relationship of this name, false otherwise.
620 sub has_relationship {
621 my ($self, $rel) = @_;
622 return exists $self->_relationships->{$rel};
625 =head2 reverse_relationship_info
629 =item Arguments: $relname
633 Returns an array of hash references of relationship information for
634 the other side of the specified relationship name.
638 sub reverse_relationship_info {
639 my ($self, $rel) = @_;
640 my $rel_info = $self->relationship_info($rel);
643 return $ret unless ((ref $rel_info->{cond}) eq 'HASH');
645 my @cond = keys(%{$rel_info->{cond}});
646 my @refkeys = map {/^\w+\.(\w+)$/} @cond;
647 my @keys = map {$rel_info->{cond}->{$_} =~ /^\w+\.(\w+)$/} @cond;
649 # Get the related result source for this relationship
650 my $othertable = $self->related_source($rel);
652 # Get all the relationships for that source that related to this source
653 # whose foreign column set are our self columns on $rel and whose self
654 # columns are our foreign columns on $rel.
655 my @otherrels = $othertable->relationships();
656 my $otherrelationship;
657 foreach my $otherrel (@otherrels) {
658 my $otherrel_info = $othertable->relationship_info($otherrel);
660 my $back = $othertable->related_source($otherrel);
661 next unless $back->source_name eq $self->source_name;
665 if (ref $otherrel_info->{cond} eq 'HASH') {
666 @othertestconds = ($otherrel_info->{cond});
668 elsif (ref $otherrel_info->{cond} eq 'ARRAY') {
669 @othertestconds = @{$otherrel_info->{cond}};
675 foreach my $othercond (@othertestconds) {
676 my @other_cond = keys(%$othercond);
677 my @other_refkeys = map {/^\w+\.(\w+)$/} @other_cond;
678 my @other_keys = map {$othercond->{$_} =~ /^\w+\.(\w+)$/} @other_cond;
679 next if (!$self->compare_relationship_keys(\@refkeys, \@other_keys) ||
680 !$self->compare_relationship_keys(\@other_refkeys, \@keys));
681 $ret->{$otherrel} = $otherrel_info;
687 =head2 compare_relationship_keys
691 =item Arguments: $keys1, $keys2
695 Returns true if both sets of keynames are the same, false otherwise.
699 sub compare_relationship_keys {
700 my ($self, $keys1, $keys2) = @_;
702 # Make sure every keys1 is in keys2
704 foreach my $key (@$keys1) {
706 foreach my $prim (@$keys2) {
715 # Make sure every key2 is in key1
717 foreach my $prim (@$keys2) {
719 foreach my $key (@$keys1) {
736 =item Arguments: $relation
740 Returns the join structure required for the related result source.
745 my ($self, $join, $alias, $seen, $force_left) = @_;
747 $force_left ||= { force => 0 };
748 if (ref $join eq 'ARRAY') {
749 return map { $self->resolve_join($_, $alias, $seen) } @$join;
750 } elsif (ref $join eq 'HASH') {
753 my $as = ($seen->{$_} ? $_.'_'.($seen->{$_}+1) : $_);
754 local $force_left->{force};
756 $self->resolve_join($_, $alias, $seen, $force_left),
757 $self->related_source($_)->resolve_join(
758 $join->{$_}, $as, $seen, $force_left
762 } elsif (ref $join) {
763 $self->throw_exception("No idea how to resolve join reftype ".ref $join);
765 my $count = ++$seen->{$join};
766 #use Data::Dumper; warn Dumper($seen);
767 my $as = ($count > 1 ? "${join}_${count}" : $join);
768 my $rel_info = $self->relationship_info($join);
769 $self->throw_exception("No such relationship ${join}") unless $rel_info;
771 if ($force_left->{force}) {
774 $type = $rel_info->{attrs}{join_type} || '';
775 $force_left->{force} = 1 if lc($type) eq 'left';
777 return [ { $as => $self->related_source($join)->from,
778 -join_type => $type },
779 $self->resolve_condition($rel_info->{cond}, $as, $alias) ];
783 =head2 resolve_condition
787 =item Arguments: $cond, $as, $alias|$object
791 Resolves the passed condition to a concrete query fragment. If given an alias,
792 returns a join condition; if given an object, inverts that object to produce
793 a related conditional from that object.
797 sub resolve_condition {
798 my ($self, $cond, $as, $for) = @_;
800 if (ref $cond eq 'HASH') {
802 foreach my $k (keys %{$cond}) {
804 # XXX should probably check these are valid columns
805 $k =~ s/^foreign\.// ||
806 $self->throw_exception("Invalid rel cond key ${k}");
808 $self->throw_exception("Invalid rel cond val ${v}");
809 if (ref $for) { # Object
810 #warn "$self $k $for $v";
811 $ret{$k} = $for->get_column($v) if $for->has_column_loaded($v);
813 } elsif (!defined $for) { # undef, i.e. "no object"
815 } elsif (ref $as eq 'HASH') { # reverse hashref
816 $ret{$v} = $as->{$k};
817 } elsif (ref $as) { # reverse object
818 $ret{$v} = $as->get_column($k);
819 } elsif (!defined $as) { # undef, i.e. "no reverse object"
822 $ret{"${as}.${k}"} = "${for}.${v}";
826 } elsif (ref $cond eq 'ARRAY') {
827 return [ map { $self->resolve_condition($_, $as, $for) } @$cond ];
829 die("Can't handle this yet :(");
833 =head2 resolve_prefetch
837 =item Arguments: hashref/arrayref/scalar
841 Accepts one or more relationships for the current source and returns an
842 array of column names for each of those relationships. Column names are
843 prefixed relative to the current source, in accordance with where they appear
844 in the supplied relationships. Examples:
846 my $source = $schema->resultset('Tag')->source;
847 @columns = $source->resolve_prefetch( { cd => 'artist' } );
855 # 'cd.artist.artistid',
859 @columns = $source->resolve_prefetch( qw[/ cd /] );
869 $source = $schema->resultset('CD')->source;
870 @columns = $source->resolve_prefetch( qw[/ artist producer /] );
876 # 'producer.producerid',
882 sub resolve_prefetch {
883 my ($self, $pre, $alias, $seen, $order, $collapse) = @_;
885 #$alias ||= $self->name;
886 #warn $alias, Dumper $pre;
887 if( ref $pre eq 'ARRAY' ) {
889 map { $self->resolve_prefetch( $_, $alias, $seen, $order, $collapse ) }
892 elsif( ref $pre eq 'HASH' ) {
895 $self->resolve_prefetch($_, $alias, $seen, $order, $collapse),
896 $self->related_source($_)->resolve_prefetch(
897 $pre->{$_}, "${alias}.$_", $seen, $order, $collapse)
903 $self->throw_exception(
904 "don't know how to resolve prefetch reftype ".ref($pre));
907 my $count = ++$seen->{$pre};
908 my $as = ($count > 1 ? "${pre}_${count}" : $pre);
909 my $rel_info = $self->relationship_info( $pre );
910 $self->throw_exception( $self->name . " has no such relationship '$pre'" )
912 my $as_prefix = ($alias =~ /^.*?\.(.+)$/ ? $1.'.' : '');
913 my $rel_source = $self->related_source($pre);
915 if (exists $rel_info->{attrs}{accessor}
916 && $rel_info->{attrs}{accessor} eq 'multi') {
917 $self->throw_exception(
918 "Can't prefetch has_many ${pre} (join cond too complex)")
919 unless ref($rel_info->{cond}) eq 'HASH';
920 my $dots = @{[$as_prefix =~ m/\./g]} + 1; # +1 to match the ".${as_prefix}"
921 if (my ($fail) = grep { @{[$_ =~ m/\./g]} == $dots }
923 my ($last) = ($fail =~ /([^\.]+)$/);
924 $self->throw_exception(
925 "Can't prefetch multiple has_many rels ${last} and ${pre}"
926 .(length($as_prefix) ? "at the same level (${as_prefix})"
930 #my @col = map { (/^self\.(.+)$/ ? ("${as_prefix}.$1") : ()); }
931 # values %{$rel_info->{cond}};
932 $collapse->{".${as_prefix}${pre}"} = [ $rel_source->primary_columns ];
933 # action at a distance. prepending the '.' allows simpler code
934 # in ResultSet->_collapse_result
935 my @key = map { (/^foreign\.(.+)$/ ? ($1) : ()); }
936 keys %{$rel_info->{cond}};
937 my @ord = (ref($rel_info->{attrs}{order_by}) eq 'ARRAY'
938 ? @{$rel_info->{attrs}{order_by}}
939 : (defined $rel_info->{attrs}{order_by}
940 ? ($rel_info->{attrs}{order_by})
942 push(@$order, map { "${as}.$_" } (@key, @ord));
945 return map { [ "${as}.$_", "${as_prefix}${pre}.$_", ] }
946 $rel_source->columns;
947 #warn $alias, Dumper (\@ret);
952 =head2 related_source
956 =item Arguments: $relname
960 Returns the result source object for the given relationship.
965 my ($self, $rel) = @_;
966 if( !$self->has_relationship( $rel ) ) {
967 $self->throw_exception("No such relationship '$rel'");
969 return $self->schema->source($self->relationship_info($rel)->{source});
976 =item Arguments: $relname
980 Returns the class name for objects in the given relationship.
985 my ($self, $rel) = @_;
986 if( !$self->has_relationship( $rel ) ) {
987 $self->throw_exception("No such relationship '$rel'");
989 return $self->schema->class($self->relationship_info($rel)->{source});
994 Returns a resultset for the given source. This will initially be created
997 $self->resultset_class->new($self, $self->resultset_attributes)
999 but is cached from then on unless resultset_class changes.
1001 =head2 resultset_class
1003 ` package My::ResultSetClass;
1004 use base 'DBIx::Class::ResultSet';
1007 $source->resultset_class('My::ResultSet::Class');
1009 Set the class of the resultset, this is useful if you want to create your
1010 own resultset methods. Create your own class derived from
1011 L<DBIx::Class::ResultSet>, and set it here. If called with no arguments,
1012 this method returns the name of the existing resultset class, if one
1015 =head2 resultset_attributes
1017 $source->resultset_attributes({ order_by => [ 'id' ] });
1019 Specify here any attributes you wish to pass to your specialised
1020 resultset. For a full list of these, please see
1021 L<DBIx::Class::ResultSet/ATTRIBUTES>.
1027 $self->throw_exception(
1028 'resultset does not take any arguments. If you want another resultset, '.
1029 'call it on the schema instead.'
1032 return $self->resultset_class->new(
1035 %{$self->{resultset_attributes}},
1036 %{$self->schema->default_resultset_attributes}
1045 =item Arguments: $source_name
1049 Set the name of the result source when it is loaded into a schema.
1050 This is usefull if you want to refer to a result source by a name other than
1053 package ArchivedBooks;
1054 use base qw/DBIx::Class/;
1055 __PACKAGE__->table('books_archive');
1056 __PACKAGE__->source_name('Books');
1058 # from your schema...
1059 $schema->resultset('Books')->find(1);
1063 Obtain a new handle to this source. Returns an instance of a
1064 L<DBIx::Class::ResultSourceHandle>.
1069 return new DBIx::Class::ResultSourceHandle({
1070 schema => $_[0]->schema,
1071 source_moniker => $_[0]->source_name
1075 =head2 throw_exception
1077 See L<DBIx::Class::Schema/"throw_exception">.
1081 sub throw_exception {
1083 if (defined $self->schema) {
1084 $self->schema->throw_exception(@_);
1090 =head2 sqlt_deploy_hook($sqlt_table)
1092 An optional sub which you can declare in your own Schema class that will get
1093 passed the L<SQL::Translator::Schema::Table> object when you deploy the schema
1094 via L</create_ddl_dir> or L</deploy>.
1096 For an example of what you can do with this, see
1097 L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To Your SQL>.
1101 Matt S. Trout <mst@shadowcatsystems.co.uk>
1105 You may distribute this code under the same terms as Perl itself.