use Carp::Clan qw/^DBIx::Class/;
use Storable;
+use Scalar::Util qw/weaken/;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/AccessorGroup/);
sub new {
my ($class, $attrs) = @_;
$class = ref $class if ref $class;
- my $new = bless({ %{$attrs || {}} }, $class);
+ my $new = bless({ %{$attrs || {}}, _resultset => undef }, $class);
$new->{resultset_class} ||= 'DBIx::Class::ResultSet';
$new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} };
$new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}];
return exists $self->_columns->{$column};
}
-=head2 column_info
+=head2 column_info
my $info = $obj->column_info($col);
return @{$self->{_ordered_columns}||[]};
}
-=head2 set_primary_key(@cols)
+=head2 set_primary_key
+
+=head3 Arguments: (@cols)
Defines one or more columns as primary key for this source. Should be
called after C<add_columns>.
Declare a unique constraint on this source. Call once for each unique
constraint. Unique constraints are used when you call C<find> on a
-L<DBIx::Class::ResultSet, only columns in the constraint are searched,
+L<DBIx::Class::ResultSet>, only columns in the constraint are searched,
# For e.g. UNIQUE (column1, column2)
__PACKAGE__->add_unique_constraint(constraint_name => [ qw/column1 column2/ ]);
1;
}
-=head2 relationships()
+=head2 relationships
Returns all valid relationship names for this source
return keys %{shift->_relationships};
}
-=head2 relationship_info($relname)
+=head2 relationship_info
+
+=head3 Arguments: ($relname)
Returns the relationship information for the specified relationship name
return $self->_relationships->{$rel};
}
-=head2 has_relationship($rel)
+=head2 has_relationship
+
+=head3 Arguments: ($rel)
Returns 1 if the source has a relationship of this name, 0 otherwise.
return exists $self->_relationships->{$rel};
}
-=head2 resolve_join($relation)
+=head2 resolve_join
+
+=head3 Arguments: ($relation)
Returns the join structure required for the related result source
}
}
-=head2 resolve_condition($cond, $as, $alias|$object)
+=head2 resolve_condition
+
+=head3 Arguments: ($cond, $as, $alias|$object)
Resolves the passed condition to a concrete query fragment. If given an alias,
returns a join condition; if given an object, inverts that object to produce
#warn "$self $k $for $v";
$ret{$k} = $for->get_column($v);
#warn %ret;
+ } elsif (ref $as) { # reverse object
+ $ret{$v} = $as->get_column($k);
} else {
$ret{"${as}.${k}"} = "${for}.${v}";
}
}
}
-=head2 resolve_prefetch (hashref/arrayref/scalar)
+=head2 resolve_prefetch
+
+=head3 Arguments: (hashref/arrayref/scalar)
Accepts one or more relationships for the current source and returns an
array of column names for each of those relationships. Column names are
}
}
-=head2 related_source($relname)
+=head2 related_source
+
+=head3 Arguments: ($relname)
Returns the result source object for the given relationship
sub resultset {
my $self = shift;
- return $self->resultset_class->new($self, $self->{resultset_attributes});
+ return $self->{_resultset} if ref $self->{_resultset} eq $self->resultset_class;
+ return $self->{_resultset} = do {
+ my $rs = $self->resultset_class->new($self, $self->{resultset_attributes});
+ weaken $rs->result_source;
+ $rs;
+ };
}
=head2 throw_exception