use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/AccessorGroup/);
-__PACKAGE__->mk_group_accessors('simple' =>
- qw/_ordered_columns _columns _primaries _unique_constraints name resultset_attributes schema from _relationships/);
-__PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class result_class/);
+__PACKAGE__->mk_group_accessors('simple' => qw/_ordered_columns
+ _columns _primaries _unique_constraints name resultset_attributes
+ schema from _relationships/);
+
+__PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class
+ result_class/);
=head1 NAME
=item is_auto_increment
Set this to a true value if this is a column that is somehow
-automatically filled. This is currently not used by DBIx::Class.
+automatically filled. This is used to determine which columns to empty
+when cloning objects using C<copy>.
=item is_foreign_key
=item sequence
-If your column is using a sequence to create it's values, set the name
-of the sequence here, to allow the values to be retrieved
-automatically by the L<DBIx::Class::PK::Auto> module. PK::Auto will
-attempt to retrieve the sequence name from the database, if this value
-is left unset.
+Sets the name of the sequence to use to generate values. If not
+specified, L<DBIx::Class::PK::Auto> will attempt to retrieve the
+name of the sequence from the database automatically.
=back
sub columns {
my $self = shift;
- $self->throw_exception("columns() is a read-only accessor, did you mean add_columns()?") if (@_ > 1);
+ $self->throw_exception(
+ "columns() is a read-only accessor, did you mean add_columns()?"
+ ) if (@_ > 1);
return @{$self->{_ordered_columns}||[]};
}
$source->add_relationship('relname', 'related_source', $cond, $attrs);
-The relation name can be arbitrary, but must be unique for each relationship
-attached to this result source. 'related_source' should be the name with
-which the related result source was registered with the current schema
-(for simple schemas this is usally either Some::Namespace::Foo or just Foo)
+The relationship name can be arbitrary, but must be unique for each
+relationship attached to this result source. 'related_source' should
+be the name with which the related result source was registered with
+the current schema. For example:
+
+ $schema->source('Book')->add_relationship('reviews', 'Review', {
+ 'foreign.book_id' => 'self.id',
+ });
-The condition needs to be an SQL::Abstract-style representation of the join
-between the tables. For example, if you're creating a rel from Author to Book,
+The condition C<$cond> needs to be an SQL::Abstract-style
+representation of the join between the tables. For example, if you're
+creating a rel from Author to Book,
{ 'foreign.author_id' => 'self.id' }
=item proxy
-An arrayref containing a list of accessors in the foreign class to
-proxy in the main class. If, for example, you do the following:
-
- __PACKAGE__->might_have(bar => 'Bar', undef, { proxy => [ qw/margle/] });
-
-Then, assuming Bar has an accessor named margle, you can do:
+An arrayref containing a list of accessors in the foreign class to proxy in
+the main class. If, for example, you do the following:
+
+ CD->might_have(liner_notes => 'LinerNotes', undef, {
+ proxy => [ qw/notes/ ],
+ });
+
+Then, assuming LinerNotes has an accessor named notes, you can do:
- my $obj = Foo->find(1);
- $obj->margle(10); # set margle; Bar object is created if it doesn't exist
+ my $cd = CD->find(1);
+ $cd->notes('Notes go here'); # set notes -- LinerNotes object is
+ # created if it doesn't exist
=item accessor
return $self->schema->source($self->relationship_info($rel)->{source});
}
+=head2 related_class
+
+=head3 Arguments: ($relname)
+
+Returns the class object for the given relationship
+
+=cut
+
+sub related_class {
+ my ($self, $rel) = @_;
+ if( !$self->has_relationship( $rel ) ) {
+ $self->throw_exception("No such relationship '$rel'");
+ }
+ return $self->schema->class($self->relationship_info($rel)->{source});
+}
+
=head2 resultset
-Returns a resultset for the given source, by calling:
+Returns a resultset for the given source. This will initially be created
+on demand by calling
$self->resultset_class->new($self, $self->resultset_attributes)
+but is cached from then on unless resultset_class changes.
+
=head2 resultset_class
Set the class of the resultset, this is useful if you want to create your