From: Rafael Kitover Date: Mon, 10 Sep 2012 14:23:18 +0000 (-0400) Subject: add rel_type param for relationship_attrs coderef X-Git-Tag: 0.07034_01~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3492170f73028981fa56f8d2f7d4c8c1aeea5bb5;p=dbsrgits%2FDBIx-Class-Schema-Loader.git add rel_type param for relationship_attrs coderef Forgot to pass some sort of param for the rel type for the relationship_attrs coderef, adding 'rel_type' with the value 'belongs_to', 'has_many' or 'might_have'. Add tests to 45relationships.t and doc in ::Base POD. --- diff --git a/Changes b/Changes index 779e1cb..ca0d77a 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - add rel_type param for relationship_attrs coderef + 0.07033 2012-09-09 16:11:47 - more thoroughly document the new behavior for relationship attributes under "relationship_attrs" in ::Base POD diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 188240c..54ebe6b 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -402,6 +402,7 @@ Can also be a coderef, for more precise control, in which case the coderef gets this hash of parameters (as a list:) rel_name # the name of the relationship + rel_type # the type of the relationship: 'belongs_to', 'has_many' or 'might_have' local_source # the DBIx::Class::ResultSource object for the source the rel is *from* remote_source # the DBIx::Class::ResultSource object for the source the rel is *to* local_table # a DBIx::Class::Schema::Loader::Table object for the table of the source the rel is from @@ -418,6 +419,7 @@ For example: my %p = @_; say "the relationship name is: $p{rel_name}"; + say "the relationship is a: $p{rel_type}"; say "the local class is: ", $p{local_source}->result_class; say "the remote class is: ", $p{remote_source}->result_class; say "the local table is: ", $p{local_table}->sql_name; diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index 6f32ff1..fac03d0 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -425,6 +425,7 @@ sub generate_code { my $rel_attrs_params = { rel_name => $remote_relname, + rel_type => $local_method, local_source => $self->schema->source($local_moniker), remote_source => $self->schema->source($remote_moniker), local_table => $rel->{local_table}, @@ -456,6 +457,7 @@ sub generate_code { $rel_attrs_params = { rel_name => $local_relname, + rel_type => $remote_method, local_source => $self->schema->source($remote_moniker), remote_source => $self->schema->source($local_moniker), local_table => $rel->{remote_table}, diff --git a/t/45relationships.t b/t/45relationships.t index 6ebdf14..b46684e 100644 --- a/t/45relationships.t +++ b/t/45relationships.t @@ -140,6 +140,7 @@ throws_ok { $relationship_attrs_coderef_invoked++; if ($p{rel_name} eq 'bars') { + is $p{rel_type}, 'has_many', 'correct rel_type'; is $p{local_table}, 'foo', 'correct local_table'; is_deeply $p{local_cols}, [ 'fooid' ], 'correct local_cols'; is $p{remote_table}, 'bar', 'correct remote_table'; @@ -162,6 +163,7 @@ throws_ok { return $p{attrs}; } elsif ($p{rel_name} eq 'fooref') { + is $p{rel_type}, 'belongs_to', 'correct rel_type'; is $p{local_table}, 'bar', 'correct local_table'; is_deeply $p{local_cols}, [ 'fooref' ], 'correct local_cols'; is $p{remote_table}, 'foo', 'correct remote_table';