1 package DBIx::Class::ResultSource;
6 use base 'DBIx::Class::ResultSource::RowParser';
9 use DBIx::Class::_Util qw(
10 UNRESOLVABLE_CONDITION
11 dbic_internal_try fail_on_internal_call
12 refdesc emit_loud_diag
14 use SQL::Abstract 'is_literal_value';
15 use Devel::GlobalDestruction;
16 use Scalar::Util qw( blessed weaken isweak refaddr );
18 # FIXME - somehow breaks ResultSetManager, do not remove until investigated
19 use DBIx::Class::ResultSet;
23 my @hashref_attributes = qw(
24 source_info resultset_attributes
25 _columns _unique_constraints _relationships
27 my @arrayref_attributes = qw(
28 _ordered_columns _primaries
30 __PACKAGE__->mk_group_accessors(rsrc_instance_specific_attribute =>
33 qw( source_name name column_info_from_storage sqlt_deploy_callback ),
36 __PACKAGE__->mk_group_accessors(rsrc_instance_specific_handler => qw(
43 DBIx::Class::ResultSource - Result source object
47 # Create a table based result source, in a result class.
49 package MyApp::Schema::Result::Artist;
50 use base qw/DBIx::Class::Core/;
52 __PACKAGE__->table('artist');
53 __PACKAGE__->add_columns(qw/ artistid name /);
54 __PACKAGE__->set_primary_key('artistid');
55 __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD');
59 # Create a query (view) based result source, in a result class
60 package MyApp::Schema::Result::Year2000CDs;
61 use base qw/DBIx::Class::Core/;
63 __PACKAGE__->load_components('InflateColumn::DateTime');
64 __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
66 __PACKAGE__->table('year2000cds');
67 __PACKAGE__->result_source->is_virtual(1);
68 __PACKAGE__->result_source->view_definition(
69 "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
75 A ResultSource is an object that represents a source of data for querying.
77 This class is a base class for various specialised types of result
78 sources, for example L<DBIx::Class::ResultSource::Table>. Table is the
79 default result source type, so one is created for you when defining a
80 result class as described in the synopsis above.
82 More specifically, the L<DBIx::Class::Core> base class pulls in the
83 L<DBIx::Class::ResultSourceProxy::Table> component, which defines
84 the L<table|DBIx::Class::ResultSourceProxy::Table/table> method.
85 When called, C<table> creates and stores an instance of
86 L<DBIx::Class::ResultSource::Table>. Luckily, to use tables as result
87 sources, you don't need to remember any of this.
89 Result sources representing select queries, or views, can also be
90 created, see L<DBIx::Class::ResultSource::View> for full details.
92 =head2 Finding result source objects
94 As mentioned above, a result source instance is created and stored for
96 L<Result Class|DBIx::Class::Manual::Glossary/Result Class>.
98 You can retrieve the result source at runtime in the following ways:
102 =item From a Schema object:
104 $schema->source($source_name);
106 =item From a Result object:
108 $result->result_source;
110 =item From a ResultSet object:
122 $class->new({attribute_name => value});
124 Creates a new ResultSource object. Not normally called directly by end users.
131 sub __derived_instances {
133 (defined $_->{weakref})
136 } values %{ $rsrc_registry->{ refaddr($_[0]) }{ derivatives } }
140 my ($class, $attrs) = @_;
141 $class = ref $class if ref $class;
143 my $ancestor = delete $attrs->{__derived_from};
145 my $self = bless { %$attrs }, $class;
148 DBIx::Class::_ENV_::ASSERT_NO_ERRONEOUS_METAINSTANCE_USE
150 # a constructor with 'name' as sole arg clearly isn't "inheriting" from anything
151 ( not ( keys(%$self) == 1 and exists $self->{name} ) )
153 defined CORE::caller(1)
155 (CORE::caller(1))[3] !~ / ::new$ | ^ DBIx::Class :: (?:
156 ResultSourceProxy::Table::table
158 ResultSourceProxy::Table::_init_result_source_instance
163 local $Carp::CarpLevel = $Carp::CarpLevel + 1
165 Carp::confess("Incorrect instantiation of '$self': you almost certainly wanted to call ->clone() instead");
168 my $own_slot = $rsrc_registry->{
169 my $own_addr = refaddr $self
170 } = { derivatives => {} };
172 weaken( $own_slot->{weakref} = $self );
177 my $ancestor_slot = $rsrc_registry->{
178 my $ancestor_addr = refaddr $ancestor
182 # on ancestry recording compact registry slots, prevent unbound growth
183 for my $r ( $rsrc_registry, map { $_->{derivatives} } values %$rsrc_registry ) {
184 defined $r->{$_}{weakref} or delete $r->{$_}
188 weaken( $_->{$own_addr} = $own_slot ) for map
189 { $_->{derivatives} }
193 { defined $_->{derivatives}{$ancestor_addr} }
194 values %$rsrc_registry
201 $self->{resultset_class} ||= 'DBIx::Class::ResultSet';
202 $self->{name} ||= "!!NAME NOT SET!!";
203 $self->{_columns_info_loaded} ||= 0;
204 $self->{sqlt_deploy_callback} ||= 'default_sqlt_deploy_hook';
206 $self->{$_} = { %{ $self->{$_} || {} } }
207 for @hashref_attributes, '__metadata_divergencies';
209 $self->{$_} = [ @{ $self->{$_} || [] } ]
210 for @arrayref_attributes;
215 sub DBIx::Class::__Rsrc_Ancestry_iThreads_handler__::CLONE {
216 for my $r ( $rsrc_registry, map { $_->{derivatives} } values %$rsrc_registry ) {
218 defined $_->{weakref}
219 ? ( refaddr $_->{weakref} => $_ )
226 # needs direct access to $rsrc_registry under an assert
228 sub set_rsrc_instance_specific_attribute {
230 # only mark if we are setting something different
235 defined( $_[0]->{$_[1]} )
247 length ref( $_[0]->{$_[1]} )
250 # both refs (the mark-on-same-ref is deliberate)
253 # both differing strings
254 $_[2] ne $_[0]->{$_[1]}
260 # need to protect $_ here
262 $_[0]->__derived_instances,
264 # DO NOT REMOVE - this blob is marking *ancestors* as tainted, here to
265 # weed out any fallout from https://github.com/dbsrgits/dbix-class/commit/9e36e3ec
266 # Note that there is no way to kill this warning, aside from never
267 # calling set_primary_key etc more than once per hierarchy
268 # (this is why the entire thing is guarded by an assert)
271 DBIx::Class::_ENV_::ASSERT_NO_ERRONEOUS_METAINSTANCE_USE
273 grep { $_[1] eq $_ } qw( _unique_constraints _primaries source_info )
277 { defined($_->{weakref}) ? $_->{weakref} : () }
279 { defined( ( $_->{derivatives}{refaddr($_[0])} || {} )->{weakref} ) }
280 values %$rsrc_registry
286 $derivative->{__metadata_divergencies}{$_[1]}{ $callsite ||= do {
289 # FIXME - this is horrible, but it's the best we can do for now
290 # Replace when Carp::Skip is written (it *MUST* take this use-case
291 # into consideration)
293 my ($cs) = DBIx::Class::Carp::__find_caller(__PACKAGE__);
295 my ($fr_num, @fr) = 1;
296 while( @fr = CORE::caller($fr_num++) ) {
297 $cs =~ /^ \Qat $fr[1] line $fr[2]\E (?: $ | \n )/x
304 # FIXME - using refdesc here isn't great, but I can't think of anything
305 # better at this moment
307 ? "@{[ refdesc $_[0] ]}->$fr[3](...) $cs"
314 $_[0]->{$_[1]} = $_[2];
318 sub get_rsrc_instance_specific_attribute {
320 $_[0]->__emit_stale_metadata_diag( $_[1] ) if (
321 ! $_[0]->{__in_rsrc_setter_callstack}
323 $_[0]->{__metadata_divergencies}{$_[1]}
330 # reuse the elaborate set logic of instance_specific_attr
331 sub set_rsrc_instance_specific_handler {
332 $_[0]->set_rsrc_instance_specific_attribute($_[1], $_[2]);
334 # trigger a load for the case of $foo->handler_accessor("bar")->new
335 $_[0]->get_rsrc_instance_specific_handler($_[1])
336 if defined wantarray;
339 # This is essentially the same logic as get_component_class
340 # (in DBIC::AccessorGroup). However the latter is a grouped
341 # accessor type, and here we are strictly after a 'simple'
342 # So we go ahead and recreate the logic as found in ::AG
343 sub get_rsrc_instance_specific_handler {
345 # emit desync warnings if any
346 my $val = $_[0]->get_rsrc_instance_specific_attribute( $_[1] );
348 # plain string means class - load it
353 # inherited CAG can't be set to undef effectively, so people may use ''
356 ! defined blessed $val
358 ! ${"${val}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"}
360 $_[0]->ensure_class_loaded($val);
362 ${"${val}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"}
363 = do { \(my $anon = 'loaded') };
370 sub __construct_stale_metadata_diag {
371 return '' unless $_[0]->{__metadata_divergencies}{$_[1]};
375 # find the CAG getter FIRST
376 # allows unlimited user-namespace overrides without screwing around with
379 @fr = CORE::caller(++$fr_num)
381 $fr[3] ne 'DBIx::Class::ResultSource::get_rsrc_instance_specific_attribute'
384 Carp::confess( "You are not supposed to call __construct_stale_metadata_diag here..." )
387 # then find the first non-local, non-private reportable callsite
389 @fr = CORE::caller(++$fr_num)
396 $fr[1] =~ /^\(eval \d+\)$/
398 $fr[3] =~ /::(?: __ANON__ | _\w+ )$/x
400 $fr[0] =~ /^DBIx::Class::ResultSource/
404 my $by = ( @fr and $fr[3] =~ s/.+::// )
405 # FIXME - using refdesc here isn't great, but I can't think of anything
406 # better at this moment
407 ? " by 'getter' @{[ refdesc $_[0] ]}->$fr[3](...)\n within the callstack beginning"
411 # Given the full stacktrace combined with the really involved callstack
412 # there is no chance the emitter will properly deduplicate this
413 # Only complain once per callsite per source
414 return( ( $by and $_[0]->{__encountered_divergencies}{$by}++ )
418 : "$_[0] (the metadata instance of source '@{[ $_[0]->source_name ]}') is "
419 . "*OUTDATED*, and does not reflect the modifications of its "
420 . "*ancestors* as follows:\n"
425 { $a->[1] cmp $b->[1] }
427 { [ $_, ( $_ =~ /( at .+? line \d+)/ ) ] }
428 keys %{ $_[0]->{__metadata_divergencies}{$_[1]} }
430 . "\nStale metadata accessed${by}"
434 sub __emit_stale_metadata_diag {
437 # short circuit: no message - no diag
438 $_[0]->__construct_stale_metadata_diag($_[1])
442 # the constructor already does deduplication
444 confess => DBIx::Class::_ENV_::ASSERT_NO_ERRONEOUS_METAINSTANCE_USE,
450 $rsrc_instance->clone( atribute_name => overriden_value );
452 A wrapper around L</new> inheriting any defaults from the callee. This method
453 also not normally invoked directly by end users.
463 ? ( %$self, __derived_from => $self )
467 (@_ == 1 and ref $_[0] eq 'HASH')
480 =item Arguments: @columns
482 =item Return Value: L<$result_source|/new>
486 $source->add_columns(qw/col1 col2 col3/);
488 $source->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
490 $source->add_columns(
491 'col1' => { data_type => 'integer', is_nullable => 1, ... },
492 'col2' => { data_type => 'text', is_auto_increment => 1, ... },
495 Adds columns to the result source. If supplied colname => hashref
496 pairs, uses the hashref as the L</column_info> for that column. Repeated
497 calls of this method will add more columns, not replace them.
499 The column names given will be created as accessor methods on your
500 L<Result|DBIx::Class::Manual::ResultClass> objects. You can change the name of the accessor
501 by supplying an L</accessor> in the column_info hash.
503 If a column name beginning with a plus sign ('+col1') is provided, the
504 attributes provided will be merged with any existing attributes for the
505 column, with the new attributes taking precedence in the case that an
506 attribute already exists. Using this without a hashref
507 (C<< $source->add_columns(qw/+col1 +col2/) >>) is legal, but useless --
508 it does the same thing it would do without the plus.
510 The contents of the column_info are not set in stone. The following
511 keys are currently recognised/used by DBIx::Class:
517 { accessor => '_name' }
519 # example use, replace standard accessor with one of your own:
521 my ($self, $value) = @_;
523 die "Name cannot contain digits!" if($value =~ /\d/);
524 $self->_name($value);
526 return $self->_name();
529 Use this to set the name of the accessor method for this column. If unset,
530 the name of the column will be used.
534 { data_type => 'integer' }
536 This contains the column type. It is automatically filled if you use the
537 L<SQL::Translator::Producer::DBIx::Class::File> producer, or the
538 L<DBIx::Class::Schema::Loader> module.
540 Currently there is no standard set of values for the data_type. Use
541 whatever your database supports.
547 The length of your column, if it is a column type that can have a size
548 restriction. This is currently only used to create tables from your
549 schema, see L<DBIx::Class::Schema/deploy>.
553 For decimal or float values you can specify an ArrayRef in order to
554 control precision, assuming your database's
555 L<SQL::Translator::Producer> supports it.
561 Set this to a true value for a column that is allowed to contain NULL
562 values, default is false. This is currently only used to create tables
563 from your schema, see L<DBIx::Class::Schema/deploy>.
565 =item is_auto_increment
567 { is_auto_increment => 1 }
569 Set this to a true value for a column whose value is somehow
570 automatically set, defaults to false. This is used to determine which
571 columns to empty when cloning objects using
572 L<DBIx::Class::Row/copy>. It is also used by
573 L<DBIx::Class::Schema/deploy>.
579 Set this to a true or false value (not C<undef>) to explicitly specify
580 if this column contains numeric data. This controls how set_column
581 decides whether to consider a column dirty after an update: if
582 C<is_numeric> is true a numeric comparison C<< != >> will take place
583 instead of the usual C<eq>
585 If not specified the storage class will attempt to figure this out on
586 first access to the column, based on the column C<data_type>. The
587 result will be cached in this attribute.
591 { is_foreign_key => 1 }
593 Set this to a true value for a column that contains a key from a
594 foreign table, defaults to false. This is currently only used to
595 create tables from your schema, see L<DBIx::Class::Schema/deploy>.
599 { default_value => \'now()' }
601 Set this to the default value which will be inserted into a column by
602 the database. Can contain either a value or a function (use a
603 reference to a scalar e.g. C<\'now()'> if you want a function). This
604 is currently only used to create tables from your schema, see
605 L<DBIx::Class::Schema/deploy>.
607 See the note on L<DBIx::Class::Row/new> for more information about possible
608 issues related to db-side default values.
612 { sequence => 'my_table_seq' }
614 Set this on a primary key column to the name of the sequence used to
615 generate a new key value. If not specified, L<DBIx::Class::PK::Auto>
616 will attempt to retrieve the name of the sequence from the database
619 =item retrieve_on_insert
621 { retrieve_on_insert => 1 }
623 For every column where this is set to true, DBIC will retrieve the RDBMS-side
624 value upon a new row insertion (normally only the autoincrement PK is
625 retrieved on insert). C<INSERT ... RETURNING> is used automatically if
626 supported by the underlying storage, otherwise an extra SELECT statement is
627 executed to retrieve the missing data.
631 { auto_nextval => 1 }
633 Set this to a true value for a column whose value is retrieved automatically
634 from a sequence or function (if supported by your Storage driver.) For a
635 sequence, if you do not use a trigger to get the nextval, you have to set the
636 L</sequence> value as well.
638 Also set this for MSSQL columns with the 'uniqueidentifier'
639 L<data_type|DBIx::Class::ResultSource/data_type> whose values you want to
640 automatically generate using C<NEWID()>, unless they are a primary key in which
641 case this will be done anyway.
645 This is used by L<DBIx::Class::Schema/deploy> and L<SQL::Translator>
646 to add extra non-generic data to the column. For example: C<< extra
647 => { unsigned => 1} >> is used by the MySQL producer to set an integer
648 column to unsigned. For more details, see
649 L<SQL::Translator::Producer::MySQL>.
657 =item Arguments: $colname, \%columninfo?
659 =item Return Value: 1/0 (true/false)
663 $source->add_column('col' => \%info);
665 Add a single column and optional column info. Uses the same column
666 info keys as L</add_columns>.
671 my ($self, @cols) = @_;
673 local $self->{__in_rsrc_setter_callstack} = 1
674 unless $self->{__in_rsrc_setter_callstack};
676 $self->_ordered_columns(\@cols) unless $self->_ordered_columns;
678 my ( @added, $colinfos );
679 my $columns = $self->_columns;
681 while (my $col = shift @cols) {
686 ( $colinfos ||= $self->columns_info )->{$col}
692 # If next entry is { ... } use that for the column info, if not
693 # use an empty hashref
695 my $new_info = shift(@cols);
696 %$column_info = (%$column_info, %$new_info);
698 push(@added, $col) unless exists $columns->{$col};
699 $columns->{$col} = $column_info;
702 push @{ $self->_ordered_columns }, @added;
703 $self->_columns($columns);
707 sub add_column :DBIC_method_is_indirect_sugar {
708 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
709 shift->add_columns(@_)
716 =item Arguments: $colname
718 =item Return Value: 1/0 (true/false)
722 if ($source->has_column($colname)) { ... }
724 Returns true if the source has a column of this name, false otherwise.
729 my ($self, $column) = @_;
730 return exists $self->_columns->{$column};
737 =item Arguments: $colname
739 =item Return Value: Hashref of info
743 my $info = $source->column_info($col);
745 Returns the column metadata hashref for a column, as originally passed
746 to L</add_columns>. See L</add_columns> above for information on the
747 contents of the hashref.
751 sub column_info :DBIC_method_is_indirect_sugar {
752 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
754 #my ($self, $column) = @_;
755 $_[0]->columns_info([ $_[1] ])->{$_[1]};
762 =item Arguments: none
764 =item Return Value: Ordered list of column names
768 my @column_names = $source->columns;
770 Returns all column names in the order they were declared to L</add_columns>.
776 $self->throw_exception(
777 "columns() is a read-only accessor, did you mean add_columns()?"
779 return @{$self->{_ordered_columns}||[]};
786 =item Arguments: \@colnames ?
788 =item Return Value: Hashref of column name/info pairs
792 my $columns_info = $source->columns_info;
794 Like L</column_info> but returns information for the requested columns. If
795 the optional column-list arrayref is omitted it returns info on all columns
796 currently defined on the ResultSource via L</add_columns>.
801 my ($self, $columns) = @_;
803 my $colinfo = $self->_columns;
806 ! $self->{_columns_info_loaded}
808 $self->column_info_from_storage
810 grep { ! $_->{data_type} } values %$colinfo
812 my $stor = dbic_internal_try { $self->schema->storage }
814 $self->{_columns_info_loaded}++;
816 # try for the case of storage without table
818 my $info = $stor->columns_info_for( $self->from );
820 { (lc $_) => $info->{$_} }
824 foreach my $col ( keys %$colinfo ) {
826 %{ $colinfo->{$col} },
827 %{ $info->{$col} || $lc_info->{lc $col} || {} }
837 if (my $inf = $colinfo->{$_}) {
841 $self->throw_exception( sprintf (
842 "No such column '%s' on source '%s'",
844 $self->source_name || $self->name || 'Unknown source...?',
850 # the shallow copy is crucial - there are exists() checks within
858 =head2 remove_columns
862 =item Arguments: @colnames
864 =item Return Value: not defined
868 $source->remove_columns(qw/col1 col2 col3/);
870 Removes the given list of columns by name, from the result source.
872 B<Warning>: Removing a column that is also used in the sources primary
873 key, or in one of the sources unique constraints, B<will> result in a
874 broken result source.
880 =item Arguments: $colname
882 =item Return Value: not defined
886 $source->remove_column('col');
888 Remove a single column by name from the result source, similar to
891 B<Warning>: Removing a column that is also used in the sources primary
892 key, or in one of the sources unique constraints, B<will> result in a
893 broken result source.
898 my ($self, @to_remove) = @_;
900 local $self->{__in_rsrc_setter_callstack} = 1
901 unless $self->{__in_rsrc_setter_callstack};
903 my $columns = $self->_columns
908 delete $columns->{$_};
912 $self->_ordered_columns([ grep { not $to_remove{$_} } @{$self->_ordered_columns} ]);
915 sub remove_column :DBIC_method_is_indirect_sugar {
916 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
917 shift->remove_columns(@_)
920 =head2 set_primary_key
924 =item Arguments: @cols
926 =item Return Value: not defined
930 Defines one or more columns as primary key for this source. Must be
931 called after L</add_columns>.
933 Additionally, defines a L<unique constraint|/add_unique_constraint>
936 Note: you normally do want to define a primary key on your sources
937 B<even if the underlying database table does not have a primary key>.
939 L<DBIx::Class::Manual::Intro/The Significance and Importance of Primary Keys>
944 sub set_primary_key {
945 my ($self, @cols) = @_;
947 local $self->{__in_rsrc_setter_callstack} = 1
948 unless $self->{__in_rsrc_setter_callstack};
950 my $colinfo = $self->columns_info(\@cols);
951 for my $col (@cols) {
952 carp_unique(sprintf (
953 "Primary key of source '%s' includes the column '%s' which has its "
954 . "'is_nullable' attribute set to true. This is a mistake and will cause "
955 . 'various Result-object operations to fail',
956 $self->source_name || $self->name || 'Unknown source...?',
958 )) if $colinfo->{$col}{is_nullable};
961 $self->_primaries(\@cols);
963 $self->add_unique_constraint(primary => \@cols);
966 =head2 primary_columns
970 =item Arguments: none
972 =item Return Value: Ordered list of primary column names
976 Read-only accessor which returns the list of primary keys, supplied by
981 sub primary_columns {
982 return @{shift->_primaries||[]};
985 # a helper method that will automatically die with a descriptive message if
986 # no pk is defined on the source in question. For internal use to save
987 # on if @pks... boilerplate
988 sub _pri_cols_or_die {
990 my @pcols = $self->primary_columns
991 or $self->throw_exception (sprintf(
992 "Operation requires a primary key to be declared on '%s' via set_primary_key",
993 # source_name is set only after schema-registration
994 $self->source_name || $self->result_class || $self->name || 'Unknown source...?',
999 # same as above but mandating single-column PK (used by relationship condition
1001 sub _single_pri_col_or_die {
1003 my ($pri, @too_many) = $self->_pri_cols_or_die;
1005 $self->throw_exception( sprintf(
1006 "Operation requires a single-column primary key declared on '%s'",
1007 $self->source_name || $self->result_class || $self->name || 'Unknown source...?',
1015 Manually define the correct sequence for your table, to avoid the overhead
1016 associated with looking up the sequence automatically. The supplied sequence
1017 will be applied to the L</column_info> of each L<primary_key|/set_primary_key>
1021 =item Arguments: $sequence_name
1023 =item Return Value: not defined
1030 my ($self,$seq) = @_;
1032 local $self->{__in_rsrc_setter_callstack} = 1
1033 unless $self->{__in_rsrc_setter_callstack};
1035 my @pks = $self->primary_columns
1038 $_->{sequence} = $seq
1039 for values %{ $self->columns_info (\@pks) };
1043 =head2 add_unique_constraint
1047 =item Arguments: $name?, \@colnames
1049 =item Return Value: not defined
1053 Declare a unique constraint on this source. Call once for each unique
1056 # For UNIQUE (column1, column2)
1057 __PACKAGE__->add_unique_constraint(
1058 constraint_name => [ qw/column1 column2/ ],
1061 Alternatively, you can specify only the columns:
1063 __PACKAGE__->add_unique_constraint([ qw/column1 column2/ ]);
1065 This will result in a unique constraint named
1066 C<table_column1_column2>, where C<table> is replaced with the table
1069 Unique constraints are used, for example, when you pass the constraint
1070 name as the C<key> attribute to L<DBIx::Class::ResultSet/find>. Then
1071 only columns in the constraint are searched.
1073 Throws an error if any of the given column names do not yet exist on
1078 sub add_unique_constraint {
1081 local $self->{__in_rsrc_setter_callstack} = 1
1082 unless $self->{__in_rsrc_setter_callstack};
1085 $self->throw_exception(
1086 'add_unique_constraint() does not accept multiple constraints, use '
1087 . 'add_unique_constraints() instead'
1092 if (ref $cols ne 'ARRAY') {
1093 $self->throw_exception (
1094 'Expecting an arrayref of constraint columns, got ' . ($cols||'NOTHING')
1098 my $name = shift @_;
1100 $name ||= $self->name_unique_constraint($cols);
1102 foreach my $col (@$cols) {
1103 $self->throw_exception("No such column $col on table " . $self->name)
1104 unless $self->has_column($col);
1107 my %unique_constraints = $self->unique_constraints;
1108 $unique_constraints{$name} = $cols;
1109 $self->_unique_constraints(\%unique_constraints);
1112 =head2 add_unique_constraints
1116 =item Arguments: @constraints
1118 =item Return Value: not defined
1122 Declare multiple unique constraints on this source.
1124 __PACKAGE__->add_unique_constraints(
1125 constraint_name1 => [ qw/column1 column2/ ],
1126 constraint_name2 => [ qw/column2 column3/ ],
1129 Alternatively, you can specify only the columns:
1131 __PACKAGE__->add_unique_constraints(
1132 [ qw/column1 column2/ ],
1133 [ qw/column3 column4/ ]
1136 This will result in unique constraints named C<table_column1_column2> and
1137 C<table_column3_column4>, where C<table> is replaced with the table name.
1139 Throws an error if any of the given column names do not yet exist on
1142 See also L</add_unique_constraint>.
1146 sub add_unique_constraints :DBIC_method_is_indirect_sugar {
1147 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
1150 my @constraints = @_;
1152 if ( !(@constraints % 2) && grep { ref $_ ne 'ARRAY' } @constraints ) {
1153 # with constraint name
1154 while (my ($name, $constraint) = splice @constraints, 0, 2) {
1155 $self->add_unique_constraint($name => $constraint);
1159 # no constraint name
1160 foreach my $constraint (@constraints) {
1161 $self->add_unique_constraint($constraint);
1166 =head2 name_unique_constraint
1170 =item Arguments: \@colnames
1172 =item Return Value: Constraint name
1176 $source->table('mytable');
1177 $source->name_unique_constraint(['col1', 'col2']);
1181 Return a name for a unique constraint containing the specified
1182 columns. The name is created by joining the table name and each column
1183 name, using an underscore character.
1185 For example, a constraint on a table named C<cd> containing the columns
1186 C<artist> and C<title> would result in a constraint name of C<cd_artist_title>.
1188 This is used by L</add_unique_constraint> if you do not specify the
1189 optional constraint name.
1193 sub name_unique_constraint {
1194 my ($self, $cols) = @_;
1196 my $name = $self->name;
1197 $name = $$name if (ref $name eq 'SCALAR');
1198 $name =~ s/ ^ [^\.]+ \. //x; # strip possible schema qualifier
1200 return join '_', $name, @$cols;
1203 =head2 unique_constraints
1207 =item Arguments: none
1209 =item Return Value: Hash of unique constraint data
1213 $source->unique_constraints();
1215 Read-only accessor which returns a hash of unique constraints on this
1218 The hash is keyed by constraint name, and contains an arrayref of
1219 column names as values.
1223 sub unique_constraints {
1224 return %{shift->_unique_constraints||{}};
1227 =head2 unique_constraint_names
1231 =item Arguments: none
1233 =item Return Value: Unique constraint names
1237 $source->unique_constraint_names();
1239 Returns the list of unique constraint names defined on this source.
1243 sub unique_constraint_names {
1246 my %unique_constraints = $self->unique_constraints;
1248 return keys %unique_constraints;
1251 =head2 unique_constraint_columns
1255 =item Arguments: $constraintname
1257 =item Return Value: List of constraint columns
1261 $source->unique_constraint_columns('myconstraint');
1263 Returns the list of columns that make up the specified unique constraint.
1267 sub unique_constraint_columns {
1268 my ($self, $constraint_name) = @_;
1270 my %unique_constraints = $self->unique_constraints;
1272 $self->throw_exception(
1273 "Unknown unique constraint $constraint_name on '" . $self->name . "'"
1274 ) unless exists $unique_constraints{$constraint_name};
1276 return @{ $unique_constraints{$constraint_name} };
1279 =head2 sqlt_deploy_callback
1283 =item Arguments: $callback_name | \&callback_code
1285 =item Return Value: $callback_name | \&callback_code
1289 __PACKAGE__->result_source->sqlt_deploy_callback('mycallbackmethod');
1293 __PACKAGE__->result_source->sqlt_deploy_callback(sub {
1294 my ($source_instance, $sqlt_table) = @_;
1298 An accessor to set a callback to be called during deployment of
1299 the schema via L<DBIx::Class::Schema/create_ddl_dir> or
1300 L<DBIx::Class::Schema/deploy>.
1302 The callback can be set as either a code reference or the name of a
1303 method in the current result class.
1305 Defaults to L</default_sqlt_deploy_hook>.
1307 Your callback will be passed the $source object representing the
1308 ResultSource instance being deployed, and the
1309 L<SQL::Translator::Schema::Table> object being created from it. The
1310 callback can be used to manipulate the table object or add your own
1311 customised indexes. If you need to manipulate a non-table object, use
1312 the L<DBIx::Class::Schema/sqlt_deploy_hook>.
1314 See L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To
1315 Your SQL> for examples.
1317 This sqlt deployment callback can only be used to manipulate
1318 SQL::Translator objects as they get turned into SQL. To execute
1319 post-deploy statements which SQL::Translator does not currently
1320 handle, override L<DBIx::Class::Schema/deploy> in your Schema class
1321 and call L<dbh_do|DBIx::Class::Storage::DBI/dbh_do>.
1323 =head2 default_sqlt_deploy_hook
1325 This is the default deploy hook implementation which checks if your
1326 current Result class has a C<sqlt_deploy_hook> method, and if present
1327 invokes it B<on the Result class directly>. This is to preserve the
1328 semantics of C<sqlt_deploy_hook> which was originally designed to expect
1329 the Result class name and the
1330 L<$sqlt_table instance|SQL::Translator::Schema::Table> of the table being
1335 sub default_sqlt_deploy_hook {
1338 my $class = $self->result_class;
1340 if ($class and $class->can('sqlt_deploy_hook')) {
1341 $class->sqlt_deploy_hook(@_);
1345 sub _invoke_sqlt_deploy_hook {
1347 if ( my $hook = $self->sqlt_deploy_callback) {
1356 =item Arguments: $classname
1358 =item Return Value: $classname
1362 use My::Schema::ResultClass::Inflator;
1365 use My::Schema::Artist;
1367 __PACKAGE__->result_class('My::Schema::ResultClass::Inflator');
1369 Set the default result class for this source. You can use this to create
1370 and use your own result inflator. See L<DBIx::Class::ResultSet/result_class>
1373 Please note that setting this to something like
1374 L<DBIx::Class::ResultClass::HashRefInflator> will make every result unblessed
1375 and make life more difficult. Inflators like those are better suited to
1376 temporary usage via L<DBIx::Class::ResultSet/result_class>.
1382 =item Arguments: none
1384 =item Return Value: L<$resultset|DBIx::Class::ResultSet>
1388 Returns a resultset for the given source. This will initially be created
1389 on demand by calling
1391 $self->resultset_class->new($self, $self->resultset_attributes)
1393 but is cached from then on unless resultset_class changes.
1395 =head2 resultset_class
1399 =item Arguments: $classname
1401 =item Return Value: $classname
1405 package My::Schema::ResultSet::Artist;
1406 use base 'DBIx::Class::ResultSet';
1409 # In the result class
1410 __PACKAGE__->resultset_class('My::Schema::ResultSet::Artist');
1413 $source->resultset_class('My::Schema::ResultSet::Artist');
1415 Set the class of the resultset. This is useful if you want to create your
1416 own resultset methods. Create your own class derived from
1417 L<DBIx::Class::ResultSet>, and set it here. If called with no arguments,
1418 this method returns the name of the existing resultset class, if one
1421 =head2 resultset_attributes
1425 =item Arguments: L<\%attrs|DBIx::Class::ResultSet/ATTRIBUTES>
1427 =item Return Value: L<\%attrs|DBIx::Class::ResultSet/ATTRIBUTES>
1431 # In the result class
1432 __PACKAGE__->resultset_attributes({ order_by => [ 'id' ] });
1435 $source->resultset_attributes({ order_by => [ 'id' ] });
1437 Store a collection of resultset attributes, that will be set on every
1438 L<DBIx::Class::ResultSet> produced from this result source.
1440 B<CAVEAT>: C<resultset_attributes> comes with its own set of issues and
1441 bugs! Notably the contents of the attributes are B<entirely static>, which
1442 greatly hinders composability (things like L<current_source_alias
1443 |DBIx::Class::ResultSet/current_source_alias> can not possibly be respected).
1444 While C<resultset_attributes> isn't deprecated per se, you are strongly urged
1445 to seek alternatives.
1447 Since relationships use attributes to link tables together, the "default"
1448 attributes you set may cause unpredictable and undesired behavior. Furthermore,
1449 the defaults B<cannot be turned off>, so you are stuck with them.
1451 In most cases, what you should actually be using are project-specific methods:
1453 package My::Schema::ResultSet::Artist;
1454 use base 'DBIx::Class::ResultSet';
1458 #__PACKAGE__->resultset_attributes({ prefetch => 'tracks' });
1461 sub with_tracks { shift->search({}, { prefetch => 'tracks' }) }
1464 $schema->resultset('Artist')->with_tracks->...
1466 This gives you the flexibility of not using it when you don't need it.
1468 For more complex situations, another solution would be to use a virtual view
1469 via L<DBIx::Class::ResultSource::View>.
1475 $self->throw_exception(
1476 'resultset does not take any arguments. If you want another resultset, '.
1477 'call it on the schema instead.'
1480 $self->resultset_class->new(
1483 ( dbic_internal_try { %{$self->schema->default_resultset_attributes} } ),
1484 %{$self->{resultset_attributes}},
1493 =item Arguments: none
1495 =item Result value: $name
1499 Returns the name of the result source, which will typically be the table
1500 name. This may be a scalar reference if the result source has a non-standard
1507 =item Arguments: $source_name
1509 =item Result value: $source_name
1513 Set an alternate name for the result source when it is loaded into a schema.
1514 This is useful if you want to refer to a result source by a name other than
1517 package ArchivedBooks;
1518 use base qw/DBIx::Class/;
1519 __PACKAGE__->table('books_archive');
1520 __PACKAGE__->source_name('Books');
1522 # from your schema...
1523 $schema->resultset('Books')->find(1);
1529 =item Arguments: none
1531 =item Return Value: FROM clause
1535 my $from_clause = $source->from();
1537 Returns an expression of the source to be supplied to storage to specify
1538 retrieval from this source. In the case of a database, the required FROM
1543 sub from { die 'Virtual method!' }
1547 Stores a hashref of per-source metadata. No specific key names
1548 have yet been standardized, the examples below are purely hypothetical
1549 and don't actually accomplish anything on their own:
1551 __PACKAGE__->source_info({
1552 "_tablespace" => 'fast_disk_array_3',
1553 "_engine" => 'InnoDB',
1560 =item Arguments: L<$schema?|DBIx::Class::Schema>
1562 =item Return Value: L<$schema|DBIx::Class::Schema>
1566 my $schema = $source->schema();
1568 Sets and/or returns the L<DBIx::Class::Schema> object to which this
1569 result source instance has been attached to.
1575 # invoke the mark-diverging logic
1576 $_[0]->set_rsrc_instance_specific_attribute( schema => $_[1] );
1579 $_[0]->get_rsrc_instance_specific_attribute( 'schema' ) || do {
1580 my $name = $_[0]->{source_name} || '_unnamed_';
1581 my $err = 'Unable to perform storage-dependent operations with a detached result source '
1582 . "(source '$name' is not associated with a schema).";
1584 $err .= ' You need to use $schema->thaw() or manually set'
1585 . ' $DBIx::Class::ResultSourceHandle::thaw_schema while thawing.'
1586 if $_[0]->{_detached_thaw};
1588 DBIx::Class::Exception->throw($err);
1597 =item Arguments: none
1599 =item Return Value: L<$storage|DBIx::Class::Storage>
1603 $source->storage->debug(1);
1605 Returns the L<storage handle|DBIx::Class::Storage> for the current schema.
1609 sub storage :DBIC_method_is_indirect_sugar {
1610 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
1611 $_[0]->schema->storage
1614 =head2 add_relationship
1618 =item Arguments: $rel_name, $related_source_name, \%cond, \%attrs?
1620 =item Return Value: 1/true if it succeeded
1624 $source->add_relationship('rel_name', 'related_source', $cond, $attrs);
1626 L<DBIx::Class::Relationship> describes a series of methods which
1627 create pre-defined useful types of relationships. Look there first
1628 before using this method directly.
1630 The relationship name can be arbitrary, but must be unique for each
1631 relationship attached to this result source. 'related_source' should
1632 be the name with which the related result source was registered with
1633 the current schema. For example:
1635 $schema->source('Book')->add_relationship('reviews', 'Review', {
1636 'foreign.book_id' => 'self.id',
1639 The condition C<$cond> needs to be an L<SQL::Abstract>-style
1640 representation of the join between the tables. For example, if you're
1641 creating a relation from Author to Book,
1643 { 'foreign.author_id' => 'self.id' }
1645 will result in the JOIN clause
1647 author me JOIN book foreign ON foreign.author_id = me.id
1649 You can specify as many foreign => self mappings as necessary.
1651 Valid attributes are as follows:
1657 Explicitly specifies the type of join to use in the relationship. Any
1658 SQL join type is valid, e.g. C<LEFT> or C<RIGHT>. It will be placed in
1659 the SQL command immediately before C<JOIN>.
1663 An arrayref containing a list of accessors in the foreign class to proxy in
1664 the main class. If, for example, you do the following:
1666 CD->might_have(liner_notes => 'LinerNotes', undef, {
1667 proxy => [ qw/notes/ ],
1670 Then, assuming LinerNotes has an accessor named notes, you can do:
1672 my $cd = CD->find(1);
1673 # set notes -- LinerNotes object is created if it doesn't exist
1674 $cd->notes('Notes go here');
1678 Specifies the type of accessor that should be created for the
1679 relationship. Valid values are C<single> (for when there is only a single
1680 related object), C<multi> (when there can be many), and C<filter> (for
1681 when there is a single related object, but you also want the relationship
1682 accessor to double as a column accessor). For C<multi> accessors, an
1683 add_to_* method is also created, which calls C<create_related> for the
1688 Throws an exception if the condition is improperly supplied, or cannot
1693 sub add_relationship {
1694 my ($self, $rel, $f_source_name, $cond, $attrs) = @_;
1696 local $self->{__in_rsrc_setter_callstack} = 1
1697 unless $self->{__in_rsrc_setter_callstack};
1699 $self->throw_exception("Can't create relationship without join condition")
1703 # Check foreign and self are right in cond
1704 if ( (ref $cond ||'') eq 'HASH') {
1705 $_ =~ /^foreign\./ or $self->throw_exception("Malformed relationship condition key '$_': must be prefixed with 'foreign.'")
1708 $_ =~ /^self\./ or $self->throw_exception("Malformed relationship condition value '$_': must be prefixed with 'self.'")
1712 my %rels = %{ $self->_relationships };
1713 $rels{$rel} = { class => $f_source_name,
1714 source => $f_source_name,
1717 $self->_relationships(\%rels);
1722 =head2 relationships
1726 =item Arguments: none
1728 =item Return Value: L<@rel_names|DBIx::Class::Relationship>
1732 my @rel_names = $source->relationships();
1734 Returns all relationship names for this source.
1739 keys %{$_[0]->_relationships};
1742 =head2 relationship_info
1746 =item Arguments: L<$rel_name|DBIx::Class::Relationship>
1748 =item Return Value: L<\%rel_data|DBIx::Class::Relationship::Base/add_relationship>
1752 Returns a hash of relationship information for the specified relationship
1753 name. The keys/values are as specified for L<DBIx::Class::Relationship::Base/add_relationship>.
1757 sub relationship_info {
1758 #my ($self, $rel) = @_;
1759 return shift->_relationships->{+shift};
1762 =head2 has_relationship
1766 =item Arguments: L<$rel_name|DBIx::Class::Relationship>
1768 =item Return Value: 1/0 (true/false)
1772 Returns true if the source has a relationship of this name, false otherwise.
1776 sub has_relationship {
1777 #my ($self, $rel) = @_;
1778 return exists shift->_relationships->{+shift};
1781 =head2 reverse_relationship_info
1785 =item Arguments: L<$rel_name|DBIx::Class::Relationship>
1787 =item Return Value: L<\%rel_data|DBIx::Class::Relationship::Base/add_relationship>
1791 Looks through all the relationships on the source this relationship
1792 points to, looking for one whose condition is the reverse of the
1793 condition on this relationship.
1795 A common use of this is to find the name of the C<belongs_to> relation
1796 opposing a C<has_many> relation. For definition of these look in
1797 L<DBIx::Class::Relationship>.
1799 The returned hashref is keyed by the name of the opposing
1800 relationship, and contains its data in the same manner as
1801 L</relationship_info>.
1805 sub reverse_relationship_info {
1806 my ($self, $rel) = @_;
1808 my $rel_info = $self->relationship_info($rel)
1809 or $self->throw_exception("No such relationship '$rel'");
1813 return $ret unless ((ref $rel_info->{cond}) eq 'HASH');
1815 my $stripped_cond = $self->__strip_relcond ($rel_info->{cond});
1817 my $registered_source_name = $self->source_name;
1819 # this may be a partial schema or something else equally esoteric
1820 my $other_rsrc = $self->related_source($rel);
1822 # Get all the relationships for that source that related to this source
1823 # whose foreign column set are our self columns on $rel and whose self
1824 # columns are our foreign columns on $rel
1825 foreach my $other_rel ($other_rsrc->relationships) {
1827 # only consider stuff that points back to us
1828 # "us" here is tricky - if we are in a schema registration, we want
1829 # to use the source_names, otherwise we will use the actual classes
1831 # the schema may be partial
1832 my $roundtrip_rsrc = dbic_internal_try { $other_rsrc->related_source($other_rel) }
1835 if ($registered_source_name) {
1836 next if $registered_source_name ne ($roundtrip_rsrc->source_name || '')
1839 next if $self->result_class ne $roundtrip_rsrc->result_class;
1842 my $other_rel_info = $other_rsrc->relationship_info($other_rel);
1844 # this can happen when we have a self-referential class
1845 next if $other_rel_info eq $rel_info;
1847 next unless ref $other_rel_info->{cond} eq 'HASH';
1848 my $other_stripped_cond = $self->__strip_relcond($other_rel_info->{cond});
1850 $ret->{$other_rel} = $other_rel_info if (
1851 $self->_compare_relationship_keys (
1852 [ keys %$stripped_cond ], [ values %$other_stripped_cond ]
1855 $self->_compare_relationship_keys (
1856 [ values %$stripped_cond ], [ keys %$other_stripped_cond ]
1864 # all this does is removes the foreign/self prefix from a condition
1865 sub __strip_relcond {
1868 { map { /^ (?:foreign|self) \. (\w+) $/x } ($_, $_[1]{$_}) }
1873 sub compare_relationship_keys {
1874 carp 'compare_relationship_keys is a private method, stop calling it';
1876 $self->_compare_relationship_keys (@_);
1879 # Returns true if both sets of keynames are the same, false otherwise.
1880 sub _compare_relationship_keys {
1881 # my ($self, $keys1, $keys2) = @_;
1883 join ("\x00", sort @{$_[1]})
1885 join ("\x00", sort @{$_[2]})
1889 # optionally takes either an arrayref of column names, or a hashref of already
1890 # retrieved colinfos
1891 # returns an arrayref of column names of the shortest unique constraint
1892 # (matching some of the input if any), giving preference to the PK
1893 sub _identifying_column_set {
1894 my ($self, $cols) = @_;
1896 my %unique = $self->unique_constraints;
1897 my $colinfos = ref $cols eq 'HASH' ? $cols : $self->columns_info($cols||());
1899 # always prefer the PK first, and then shortest constraints first
1901 for my $set (delete $unique{primary}, sort { @$a <=> @$b } (values %unique) ) {
1902 next unless $set && @$set;
1905 next USET unless ($colinfos->{$_} && !$colinfos->{$_}{is_nullable} );
1908 # copy so we can mangle it at will
1915 sub _minimal_valueset_satisfying_constraint {
1917 my $args = { ref $_[0] eq 'HASH' ? %{ $_[0] } : @_ };
1919 $args->{columns_info} ||= $self->columns_info;
1921 my $vals = $self->schema->storage->_extract_fixed_condition_columns(
1923 ($args->{carp_on_nulls} ? 'consider_nulls' : undef ),
1927 for my $col ($self->unique_constraint_columns($args->{constraint_name}) ) {
1928 if( ! exists $vals->{$col} or ( $vals->{$col}||'' ) eq UNRESOLVABLE_CONDITION ) {
1929 $cols->{missing}{$col} = undef;
1931 elsif( ! defined $vals->{$col} ) {
1932 $cols->{$args->{carp_on_nulls} ? 'undefined' : 'missing'}{$col} = undef;
1935 # we need to inject back the '=' as _extract_fixed_condition_columns
1936 # will strip it from literals and values alike, resulting in an invalid
1937 # condition in the end
1938 $cols->{present}{$col} = { '=' => $vals->{$col} };
1941 $cols->{fc}{$col} = 1 if (
1942 ( ! $cols->{missing} or ! exists $cols->{missing}{$col} )
1944 keys %{ $args->{columns_info}{$col}{_filter_info} || {} }
1948 $self->throw_exception( sprintf ( "Unable to satisfy requested constraint '%s', missing values for column(s): %s",
1949 $args->{constraint_name},
1950 join (', ', map { "'$_'" } sort keys %{$cols->{missing}} ),
1951 ) ) if $cols->{missing};
1953 $self->throw_exception( sprintf (
1954 "Unable to satisfy requested constraint '%s', FilterColumn values not usable for column(s): %s",
1955 $args->{constraint_name},
1956 join (', ', map { "'$_'" } sort keys %{$cols->{fc}}),
1962 !$ENV{DBIC_NULLABLE_KEY_NOWARN}
1964 carp_unique ( sprintf (
1965 "NULL/undef values supplied for requested unique constraint '%s' (NULL "
1966 . 'values in column(s): %s). This is almost certainly not what you wanted, '
1967 . 'though you can set DBIC_NULLABLE_KEY_NOWARN to disable this warning.',
1968 $args->{constraint_name},
1969 join (', ', map { "'$_'" } sort keys %{$cols->{undefined}}),
1973 return { map { %{ $cols->{$_}||{} } } qw(present undefined) };
1976 # Returns the {from} structure used to express JOIN conditions
1978 my ($self, $join, $alias, $seen, $jpath, $parent_force_left) = @_;
1980 # we need a supplied one, because we do in-place modifications, no returns
1981 $self->throw_exception ('You must supply a seen hashref as the 3rd argument to _resolve_join')
1982 unless ref $seen eq 'HASH';
1984 $self->throw_exception ('You must supply a joinpath arrayref as the 4th argument to _resolve_join')
1985 unless ref $jpath eq 'ARRAY';
1987 $jpath = [@$jpath]; # copy
1989 if (not defined $join or not length $join) {
1992 elsif (ref $join eq 'ARRAY') {
1995 $self->_resolve_join($_, $alias, $seen, $jpath, $parent_force_left);
1998 elsif (ref $join eq 'HASH') {
2001 for my $rel (keys %$join) {
2003 my $rel_info = $self->relationship_info($rel)
2004 or $self->throw_exception("No such relationship '$rel' on " . $self->source_name);
2006 my $force_left = $parent_force_left;
2007 $force_left ||= lc($rel_info->{attrs}{join_type}||'') eq 'left';
2009 # the actual seen value will be incremented by the recursion
2010 my $as = $self->schema->storage->relname_to_table_alias(
2011 $rel, ($seen->{$rel} && $seen->{$rel} + 1)
2015 $self->_resolve_join($rel, $alias, $seen, [@$jpath], $force_left),
2016 $self->related_source($rel)->_resolve_join(
2017 $join->{$rel}, $as, $seen, [@$jpath, { $rel => $as }], $force_left
2025 $self->throw_exception("No idea how to resolve join reftype ".ref $join);
2028 my $count = ++$seen->{$join};
2029 my $as = $self->schema->storage->relname_to_table_alias(
2030 $join, ($count > 1 && $count)
2033 my $rel_info = $self->relationship_info($join)
2034 or $self->throw_exception("No such relationship $join on " . $self->source_name);
2036 my $rel_src = $self->related_source($join);
2037 return [ { $as => $rel_src->from,
2039 -join_type => $parent_force_left
2041 : $rel_info->{attrs}{join_type}
2043 -join_path => [@$jpath, { $join => $as } ],
2045 ! $rel_info->{attrs}{accessor}
2047 $rel_info->{attrs}{accessor} eq 'single'
2049 $rel_info->{attrs}{accessor} eq 'filter'
2052 -relation_chain_depth => ( $seen->{-relation_chain_depth} || 0 ) + 1,
2054 $self->_resolve_relationship_condition(
2056 self_alias => $alias,
2057 foreign_alias => $as,
2064 carp 'pk_depends_on is a private method, stop calling it';
2066 $self->_pk_depends_on (@_);
2069 # Determines whether a relation is dependent on an object from this source
2070 # having already been inserted. Takes the name of the relationship and a
2071 # hashref of columns of the related object.
2072 sub _pk_depends_on {
2073 my ($self, $rel_name, $rel_data) = @_;
2075 my $relinfo = $self->relationship_info($rel_name);
2077 # don't assume things if the relationship direction is specified
2078 return $relinfo->{attrs}{is_foreign_key_constraint}
2079 if exists ($relinfo->{attrs}{is_foreign_key_constraint});
2081 my $cond = $relinfo->{cond};
2082 return 0 unless ref($cond) eq 'HASH';
2084 # map { foreign.foo => 'self.bar' } to { bar => 'foo' }
2085 my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond };
2087 # assume anything that references our PK probably is dependent on us
2088 # rather than vice versa, unless the far side is (a) defined or (b)
2090 my $rel_source = $self->related_source($rel_name);
2094 foreach my $p ($self->primary_columns) {
2096 exists $keyhash->{$p}
2098 ! defined( $rel_data->{$keyhash->{$p}} )
2100 ! ( $colinfos ||= $rel_source->columns_info )
2101 ->{$keyhash->{$p}}{is_auto_increment}
2108 sub resolve_condition {
2109 carp 'resolve_condition is a private method, stop calling it';
2110 shift->_resolve_condition (@_);
2113 sub _resolve_condition {
2114 # carp_unique sprintf
2115 # '_resolve_condition is a private method, and moreover is about to go '
2116 # . 'away. Please contact the development team at %s if you believe you '
2117 # . 'have a genuine use for this method, in order to discuss alternatives.',
2118 # DBIx::Class::_ENV_::HELP_URL,
2121 #######################
2122 ### API Design? What's that...? (a backwards compatible shim, kill me now)
2124 my ($self, $cond, @res_args, $rel_name);
2126 # we *SIMPLY DON'T KNOW YET* which arg is which, yay
2127 ($self, $cond, $res_args[0], $res_args[1], $rel_name) = @_;
2129 # assume that an undef is an object-like unset (set_from_related(undef))
2130 my @is_objlike = map { ! defined $_ or length ref $_ } (@res_args);
2132 # turn objlike into proper objects for saner code further down
2134 next unless $is_objlike[$_];
2136 if ( defined blessed $res_args[$_] ) {
2138 # but wait - there is more!!! WHAT THE FUCK?!?!?!?!
2139 if ($res_args[$_]->isa('DBIx::Class::ResultSet')) {
2140 carp('Passing a resultset for relationship resolution makes no sense - invoking __gremlins__');
2141 $is_objlike[$_] = 0;
2142 $res_args[$_] = '__gremlins__';
2146 $res_args[$_] ||= {};
2148 # hate everywhere - have to pass in as a plain hash
2149 # pretending to be an object at least for now
2150 $self->throw_exception("Unsupported object-like structure encountered: $res_args[$_]")
2151 unless ref $res_args[$_] eq 'HASH';
2156 # where-is-waldo block guesses relname, then further down we override it if available
2158 $is_objlike[1] ? ( rel_name => $res_args[0], self_alias => $res_args[0], foreign_alias => 'me', self_result_object => $res_args[1] )
2159 : $is_objlike[0] ? ( rel_name => $res_args[1], self_alias => 'me', foreign_alias => $res_args[1], foreign_values => $res_args[0] )
2160 : ( rel_name => $res_args[0], self_alias => $res_args[1], foreign_alias => $res_args[0] )
2163 ( $rel_name ? ( rel_name => $rel_name ) : () ),
2166 # Allowing passing relconds different than the relationshup itself is cute,
2167 # but likely dangerous. Remove that from the (still unofficial) API of
2168 # _resolve_relationship_condition, and instead make it "hard on purpose"
2169 local $self->relationship_info( $args->{rel_name} )->{cond} = $cond if defined $cond;
2171 #######################
2173 # now it's fucking easy isn't it?!
2174 my $rc = $self->_resolve_relationship_condition( $args );
2177 ( $rc->{join_free_condition} || $rc->{condition} ),
2178 ! $rc->{join_free_condition},
2181 # _resolve_relationship_condition always returns qualified cols even in the
2182 # case of join_free_condition, but nothing downstream expects this
2183 if ($rc->{join_free_condition} and ref $res[0] eq 'HASH') {
2185 { ($_ =~ /\.(.+)/) => $res[0]{$_} }
2191 return wantarray ? @res : $res[0];
2194 # Keep this indefinitely. There is evidence of both CPAN and
2195 # darkpan using it, and there isn't much harm in an extra var
2197 our $UNRESOLVABLE_CONDITION = UNRESOLVABLE_CONDITION;
2198 # YES I KNOW THIS IS EVIL
2199 # it is there to save darkpan from themselves, since internally
2200 # we are moving to a constant
2201 Internals::SvREADONLY($UNRESOLVABLE_CONDITION => 1);
2203 # Resolves the passed condition to a concrete query fragment and extra
2206 ## self-explanatory API, modeled on the custom cond coderef:
2207 # rel_name => (scalar)
2208 # foreign_alias => (scalar)
2209 # foreign_values => (either not supplied, or a hashref, or a foreign ResultObject (to be ->get_columns()ed), or plain undef )
2210 # self_alias => (scalar)
2211 # self_result_object => (either not supplied or a result object)
2212 # require_join_free_condition => (boolean, throws on failure to construct a JF-cond)
2213 # infer_values_based_on => (either not supplied or a hashref, implies require_join_free_condition)
2216 # condition => (a valid *likely fully qualified* sqla cond structure)
2217 # identity_map => (a hashref of foreign-to-self *unqualified* column equality names)
2218 # join_free_condition => (a valid *fully qualified* sqla cond structure, maybe unset)
2219 # inferred_values => (in case of an available join_free condition, this is a hashref of
2220 # *unqualified* column/value *EQUALITY* pairs, representing an amalgamation
2221 # of the JF-cond parse and infer_values_based_on
2222 # always either complete or unset)
2224 sub _resolve_relationship_condition {
2227 my $args = { ref $_[0] eq 'HASH' ? %{ $_[0] } : @_ };
2229 for ( qw( rel_name self_alias foreign_alias ) ) {
2230 $self->throw_exception("Mandatory argument '$_' to _resolve_relationship_condition() is not a plain string")
2231 if !defined $args->{$_} or length ref $args->{$_};
2234 $self->throw_exception("Arguments 'self_alias' and 'foreign_alias' may not be identical")
2235 if $args->{self_alias} eq $args->{foreign_alias};
2238 my $exception_rel_id = "relationship '$args->{rel_name}' on source '@{[ $self->source_name ]}'";
2240 my $rel_info = $self->relationship_info($args->{rel_name})
2242 # or $self->throw_exception( "No such $exception_rel_id" );
2243 or carp_unique("Requesting resolution on non-existent relationship '$args->{rel_name}' on source '@{[ $self->source_name ]}': fix your code *soon*, as it will break with the next major version");
2246 $exception_rel_id = "relationship '$rel_info->{_original_name}' on source '@{[ $self->source_name ]}'"
2247 if $rel_info and exists $rel_info->{_original_name};
2249 $self->throw_exception("No practical way to resolve $exception_rel_id between two data structures")
2250 if exists $args->{self_result_object} and exists $args->{foreign_values};
2252 $self->throw_exception( "Argument to infer_values_based_on must be a hash" )
2253 if exists $args->{infer_values_based_on} and ref $args->{infer_values_based_on} ne 'HASH';
2255 $args->{require_join_free_condition} ||= !!$args->{infer_values_based_on};
2257 $self->throw_exception( "Argument 'self_result_object' must be an object inheriting from DBIx::Class::Row" )
2259 exists $args->{self_result_object}
2261 ( ! defined blessed $args->{self_result_object} or ! $args->{self_result_object}->isa('DBIx::Class::Row') )
2265 my $rel_rsrc = $self->related_source($args->{rel_name});
2266 my $storage = $self->schema->storage;
2268 if (exists $args->{foreign_values}) {
2270 if (! defined $args->{foreign_values} ) {
2271 # fallback: undef => {}
2272 $args->{foreign_values} = {};
2274 elsif (defined blessed $args->{foreign_values}) {
2276 $self->throw_exception( "Objects supplied as 'foreign_values' ($args->{foreign_values}) must inherit from DBIx::Class::Row" )
2277 unless $args->{foreign_values}->isa('DBIx::Class::Row');
2280 "Objects supplied as 'foreign_values' ($args->{foreign_values}) "
2281 . "usually should inherit from the related ResultClass ('@{[ $rel_rsrc->result_class ]}'), "
2282 . "perhaps you've made a mistake invoking the condition resolver?"
2283 ) unless $args->{foreign_values}->isa($rel_rsrc->result_class);
2285 $args->{foreign_values} = { $args->{foreign_values}->get_columns };
2287 elsif ( ref $args->{foreign_values} eq 'HASH' ) {
2289 # re-build {foreign_values} excluding identically named rels
2290 if( keys %{$args->{foreign_values}} ) {
2292 my ($col_idx, $rel_idx) = map
2293 { { map { $_ => 1 } $rel_rsrc->$_ } }
2294 qw( columns relationships )
2297 my $equivalencies = $storage->_extract_fixed_condition_columns(
2298 $args->{foreign_values},
2302 $args->{foreign_values} = { map {
2303 # skip if relationship *and* a non-literal ref
2304 # this means a multicreate stub was passed in
2308 length ref $args->{foreign_values}{$_}
2310 ! is_literal_value($args->{foreign_values}{$_})
2315 ? $self->throw_exception( "Key '$_' supplied as 'foreign_values' is not a column on related source '@{[ $rel_rsrc->source_name ]}'" )
2316 : ( !exists $equivalencies->{$_} or ($equivalencies->{$_}||'') eq UNRESOLVABLE_CONDITION )
2317 ? $self->throw_exception( "Value supplied for '...{foreign_values}{$_}' is not a direct equivalence expression" )
2318 : $args->{foreign_values}{$_}
2320 } keys %{$args->{foreign_values}} };
2324 $self->throw_exception(
2325 "Argument 'foreign_values' must be either an object inheriting from '@{[ $rel_rsrc->result_class ]}', "
2326 . "or a hash reference, or undef"
2333 if (ref $rel_info->{cond} eq 'CODE') {
2336 rel_name => $args->{rel_name},
2337 self_resultsource => $self,
2338 self_alias => $args->{self_alias},
2339 foreign_alias => $args->{foreign_alias},
2341 { (exists $args->{$_}) ? ( $_ => $args->{$_} ) : () }
2342 qw( self_result_object foreign_values )
2346 # legacy - never remove these!!!
2347 $cref_args->{foreign_relname} = $cref_args->{rel_name};
2349 $cref_args->{self_rowobj} = $cref_args->{self_result_object}
2350 if exists $cref_args->{self_result_object};
2352 ($ret->{condition}, $ret->{join_free_condition}, my @extra) = $rel_info->{cond}->($cref_args);
2355 $self->throw_exception("A custom condition coderef can return at most 2 conditions, but $exception_rel_id returned extra values: @extra")
2358 if (my $jfc = $ret->{join_free_condition}) {
2360 $self->throw_exception (
2361 "The join-free condition returned for $exception_rel_id must be a hash reference"
2362 ) unless ref $jfc eq 'HASH';
2364 my ($joinfree_alias, $joinfree_source);
2365 if (defined $args->{self_result_object}) {
2366 $joinfree_alias = $args->{foreign_alias};
2367 $joinfree_source = $rel_rsrc;
2369 elsif (defined $args->{foreign_values}) {
2370 $joinfree_alias = $args->{self_alias};
2371 $joinfree_source = $self;
2374 # FIXME sanity check until things stabilize, remove at some point
2375 $self->throw_exception (
2376 "A join-free condition returned for $exception_rel_id without a result object to chain from"
2377 ) unless $joinfree_alias;
2379 my $fq_col_list = { map
2380 { ( "$joinfree_alias.$_" => 1 ) }
2381 $joinfree_source->columns
2384 exists $fq_col_list->{$_} or $self->throw_exception (
2385 "The join-free condition returned for $exception_rel_id may only "
2386 . 'contain keys that are fully qualified column names of the corresponding source '
2387 . "'$joinfree_alias' (instead it returned '$_')"
2395 $_->isa('DBIx::Class::Row')
2397 $self->throw_exception (
2398 "The join-free condition returned for $exception_rel_id may not "
2399 . 'contain result objects as values - perhaps instead of invoking '
2400 . '->$something you meant to return ->get_column($something)'
2406 elsif (ref $rel_info->{cond} eq 'HASH') {
2408 # the condition is static - use parallel arrays
2409 # for a "pivot" depending on which side of the
2410 # rel did we get as an object
2411 my (@f_cols, @l_cols);
2412 for my $fc (keys %{ $rel_info->{cond} }) {
2413 my $lc = $rel_info->{cond}{$fc};
2415 # FIXME STRICTMODE should probably check these are valid columns
2416 $fc =~ s/^foreign\.// ||
2417 $self->throw_exception("Invalid rel cond key '$fc'");
2419 $lc =~ s/^self\.// ||
2420 $self->throw_exception("Invalid rel cond val '$lc'");
2426 # construct the crosstable condition and the identity map
2428 $ret->{condition}{"$args->{foreign_alias}.$f_cols[$_]"} = { -ident => "$args->{self_alias}.$l_cols[$_]" };
2429 $ret->{identity_map}{$l_cols[$_]} = $f_cols[$_];
2432 if ($args->{foreign_values}) {
2433 $ret->{join_free_condition}{"$args->{self_alias}.$l_cols[$_]"} = $args->{foreign_values}{$f_cols[$_]}
2436 elsif (defined $args->{self_result_object}) {
2438 for my $i (0..$#l_cols) {
2439 if ( $args->{self_result_object}->has_column_loaded($l_cols[$i]) ) {
2440 $ret->{join_free_condition}{"$args->{foreign_alias}.$f_cols[$i]"} = $args->{self_result_object}->get_column($l_cols[$i]);
2443 $self->throw_exception(sprintf
2444 "Unable to resolve relationship '%s' from object '%s': column '%s' not "
2445 . 'loaded from storage (or not passed to new() prior to insert()). You '
2446 . 'probably need to call ->discard_changes to get the server-side defaults '
2447 . 'from the database.',
2449 $args->{self_result_object},
2451 ) if $args->{self_result_object}->in_storage;
2453 # FIXME - temporarly force-override
2454 delete $args->{require_join_free_condition};
2455 $ret->{join_free_condition} = UNRESOLVABLE_CONDITION;
2461 elsif (ref $rel_info->{cond} eq 'ARRAY') {
2462 if (@{ $rel_info->{cond} } == 0) {
2464 condition => UNRESOLVABLE_CONDITION,
2465 join_free_condition => UNRESOLVABLE_CONDITION,
2469 my @subconds = map {
2470 local $rel_info->{cond} = $_;
2471 $self->_resolve_relationship_condition( $args );
2472 } @{ $rel_info->{cond} };
2474 if( @{ $rel_info->{cond} } == 1 ) {
2475 $ret = $subconds[0];
2478 # we are discarding inferred values here... likely incorrect...
2479 # then again - the entire thing is an OR, so we *can't* use them anyway
2480 for my $subcond ( @subconds ) {
2481 $self->throw_exception('Either all or none of the OR-condition members must resolve to a join-free condition')
2482 if ( $ret and ( $ret->{join_free_condition} xor $subcond->{join_free_condition} ) );
2484 $subcond->{$_} and push @{$ret->{$_}}, $subcond->{$_} for (qw(condition join_free_condition));
2490 $self->throw_exception ("Can't handle condition $rel_info->{cond} for $exception_rel_id yet :(");
2494 $args->{require_join_free_condition}
2496 ( ! $ret->{join_free_condition} or $ret->{join_free_condition} eq UNRESOLVABLE_CONDITION )
2498 $self->throw_exception(
2499 ucfirst sprintf "$exception_rel_id does not resolve to a %sjoin-free condition fragment",
2500 exists $args->{foreign_values}
2501 ? "'foreign_values'-based reversed-"
2506 # we got something back - sanity check and infer values if we can
2509 $ret->{join_free_condition}
2511 $ret->{join_free_condition} ne UNRESOLVABLE_CONDITION
2513 my $jfc = $storage->_collapse_cond( $ret->{join_free_condition} )
2516 my $jfc_eqs = $storage->_extract_fixed_condition_columns($jfc, 'consider_nulls');
2518 if (keys %$jfc_eqs) {
2521 # $jfc is fully qualified by definition
2522 my ($col) = $_ =~ /\.(.+)/;
2524 if (exists $jfc_eqs->{$_} and ($jfc_eqs->{$_}||'') ne UNRESOLVABLE_CONDITION) {
2525 $ret->{inferred_values}{$col} = $jfc_eqs->{$_};
2527 elsif ( !$args->{infer_values_based_on} or ! exists $args->{infer_values_based_on}{$col} ) {
2528 push @nonvalues, $col;
2533 delete $ret->{inferred_values} if @nonvalues;
2537 # did the user explicitly ask
2538 if ($args->{infer_values_based_on}) {
2540 $self->throw_exception(sprintf (
2541 "Unable to complete value inferrence - custom $exception_rel_id returns conditions instead of values for column(s): %s",
2542 map { "'$_'" } @nonvalues
2546 $ret->{inferred_values} ||= {};
2548 $ret->{inferred_values}{$_} = $args->{infer_values_based_on}{$_}
2549 for keys %{$args->{infer_values_based_on}};
2552 # add the identities based on the main condition
2553 # (may already be there, since easy to calculate on the fly in the HASH case)
2554 if ( ! $ret->{identity_map} ) {
2556 my $col_eqs = $storage->_extract_fixed_condition_columns($ret->{condition});
2559 for my $lhs (keys %$col_eqs) {
2561 next if $col_eqs->{$lhs} eq UNRESOLVABLE_CONDITION;
2563 # there is no way to know who is right and who is left in a cref
2564 # therefore a full blown resolution call, and figure out the
2565 # direction a bit further below
2566 $colinfos ||= $storage->_resolve_column_info([
2567 { -alias => $args->{self_alias}, -rsrc => $self },
2568 { -alias => $args->{foreign_alias}, -rsrc => $rel_rsrc },
2571 next unless $colinfos->{$lhs}; # someone is engaging in witchcraft
2573 if ( my $rhs_ref = is_literal_value( $col_eqs->{$lhs} ) ) {
2576 $colinfos->{$rhs_ref->[0]}
2578 $colinfos->{$lhs}{-source_alias} ne $colinfos->{$rhs_ref->[0]}{-source_alias}
2580 ( $colinfos->{$lhs}{-source_alias} eq $args->{self_alias} )
2581 ? ( $ret->{identity_map}{$colinfos->{$lhs}{-colname}} = $colinfos->{$rhs_ref->[0]}{-colname} )
2582 : ( $ret->{identity_map}{$colinfos->{$rhs_ref->[0]}{-colname}} = $colinfos->{$lhs}{-colname} )
2587 $col_eqs->{$lhs} =~ /^ ( \Q$args->{self_alias}\E \. .+ ) /x
2589 ($colinfos->{$1}||{})->{-result_source} == $rel_rsrc
2591 my ($lcol, $rcol) = map
2592 { $colinfos->{$_}{-colname} }
2596 "The $exception_rel_id specifies equality of column '$lcol' and the "
2597 . "*VALUE* '$rcol' (you did not use the { -ident => ... } operator)"
2603 # FIXME - temporary, to fool the idiotic check in SQLMaker::_join_condition
2604 $ret->{condition} = { -and => [ $ret->{condition} ] }
2605 unless $ret->{condition} eq UNRESOLVABLE_CONDITION;
2610 =head2 related_source
2614 =item Arguments: $rel_name
2616 =item Return Value: $source
2620 Returns the result source object for the given relationship.
2624 sub related_source {
2625 my ($self, $rel) = @_;
2626 if( !$self->has_relationship( $rel ) ) {
2627 $self->throw_exception("No such relationship '$rel' on " . $self->source_name);
2630 # if we are not registered with a schema - just use the prototype
2631 # however if we do have a schema - ask for the source by name (and
2632 # throw in the process if all fails)
2633 if (my $schema = dbic_internal_try { $self->schema }) {
2634 $schema->source($self->relationship_info($rel)->{source});
2637 my $class = $self->relationship_info($rel)->{class};
2638 $self->ensure_class_loaded($class);
2639 $class->result_source;
2643 =head2 related_class
2647 =item Arguments: $rel_name
2649 =item Return Value: $classname
2653 Returns the class name for objects in the given relationship.
2658 my ($self, $rel) = @_;
2659 if( !$self->has_relationship( $rel ) ) {
2660 $self->throw_exception("No such relationship '$rel' on " . $self->source_name);
2662 return $self->schema->class($self->relationship_info($rel)->{source});
2669 =item Arguments: none
2671 =item Return Value: L<$source_handle|DBIx::Class::ResultSourceHandle>
2675 Obtain a new L<result source handle instance|DBIx::Class::ResultSourceHandle>
2676 for this source. Used as a serializable pointer to this resultsource, as it is not
2677 easy (nor advisable) to serialize CODErefs which may very well be present in e.g.
2678 relationship definitions.
2683 require DBIx::Class::ResultSourceHandle;
2684 return DBIx::Class::ResultSourceHandle->new({
2685 source_moniker => $_[0]->source_name,
2687 # so that a detached thaw can be re-frozen
2688 $_[0]->{_detached_thaw}
2689 ? ( _detached_source => $_[0] )
2690 : ( schema => $_[0]->schema )
2695 my $global_phase_destroy;
2697 ### NO detected_reinvoked_destructor check
2698 ### This code very much relies on being called multuple times
2700 return if $global_phase_destroy ||= in_global_destruction;
2706 # Under no circumstances shall $_[0] be stored anywhere else (like copied to
2707 # a lexical variable, or shifted, or anything else). Doing so will mess up
2708 # the refcount of this particular result source, and will allow the $schema
2709 # we are trying to save to reattach back to the source we are destroying.
2710 # The relevant code checking refcounts is in ::Schema::DESTROY()
2712 # if we are not a schema instance holder - we don't matter
2714 ! ref $_[0]->{schema}
2716 isweak $_[0]->{schema}
2719 # weaken our schema hold forcing the schema to find somewhere else to live
2720 # during global destruction (if we have not yet bailed out) this will throw
2721 # which will serve as a signal to not try doing anything else
2722 # however beware - on older perls the exception seems randomly untrappable
2723 # due to some weird race condition during thread joining :(((
2724 local $SIG{__DIE__} if $SIG{__DIE__};
2725 local $@ if DBIx::Class::_ENV_::UNSTABLE_DOLLARAT;
2727 weaken $_[0]->{schema};
2729 # if schema is still there reintroduce ourselves with strong refs back to us
2730 if ($_[0]->{schema}) {
2731 my $srcregs = $_[0]->{schema}->source_registrations;
2733 defined $srcregs->{$_}
2735 $srcregs->{$_} == $_[0]
2737 $srcregs->{$_} = $_[0]
2745 $global_phase_destroy = 1;
2748 # Dummy NEXTSTATE ensuring the all temporaries on the stack are garbage
2749 # collected before leaving this scope. Depending on the code above, this
2750 # may very well be just a preventive measure guarding future modifications
2754 sub STORABLE_freeze { Storable::nfreeze($_[0]->handle) }
2757 my ($self, $cloning, $ice) = @_;
2758 %$self = %{ (Storable::thaw($ice))->resolve };
2761 =head2 throw_exception
2763 See L<DBIx::Class::Schema/"throw_exception">.
2767 sub throw_exception {
2771 ? $self->{schema}->throw_exception(@_)
2772 : DBIx::Class::Exception->throw(@_)
2776 =head2 column_info_from_storage
2780 =item Arguments: 1/0 (default: 0)
2782 =item Return Value: 1/0
2786 __PACKAGE__->column_info_from_storage(1);
2788 Enables the on-demand automatic loading of the above column
2789 metadata from storage as necessary. This is *deprecated*, and
2790 should not be used. It will be removed before 1.0.
2792 =head1 FURTHER QUESTIONS?
2794 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
2796 =head1 COPYRIGHT AND LICENSE
2798 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
2799 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
2800 redistribute it and/or modify it under the same terms as the
2801 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.