X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;fp=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=0be9dba409311c46775632cd2c6674d7b235303d;hb=7b6a8d73e16b9b33bc8feb216b7bc8428cd7518b;hp=d1329d91879148ea4c6e6fe257ba69dcb4b48a05;hpb=a04e5e2cd5adbde04100b3cb0900ba75adc75f99;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index d1329d9..0be9dba 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -380,18 +380,55 @@ same database and schema as the table/column whose comment is being retrieved. =head2 relationship_attrs -Hashref of attributes to pass to each generated relationship, listed -by type. Also supports relationship type 'all', containing options to -pass to all generated relationships. Attributes set for more specific -relationship types override those set in 'all'. +Hashref of attributes to pass to each generated relationship, listed by type. +Also supports relationship type 'all', containing options to pass to all +generated relationships. Attributes set for more specific relationship types +override those set in 'all', and any attributes specified by this option +override the introspected attributes of the foreign key if any. For example: relationship_attrs => { - belongs_to => { is_deferrable => 0 }, + has_many => { cascade_delete => 1, cascade_copy => 1 }, }, -use this to turn off DEFERRABLE on your foreign key constraints. +use this to turn L cascades to on on your +L relationships, they default to +off. + +Can also be a coderef, for more precise control, in which case the coderef gets +this hash of parameters: + + rel_name # the name of the relationship + 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 + local_cols # an arrayref of column names of columns used in the rel in the source it is from + remote_table # a DBIx::Class::Schema::Loader::Table object for the table of the source the rel is to + remote_cols # an arrayref of column names of columns used in the rel in the source it is to + attrs # the attributes that would be set + +it should return the new hashref of attributes, or nothing for no changes. + +For example: + + relationship_attrs => sub { + my %p = @_; + + say "the relationship name is: $p{rel_name}"; + 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; + say "the rel columns in the local table are: ", (join ", ", @{$p{local_cols}}); + say "the remote table is: ", $p{remote_table}->sql_name; + say "the rel columns in the remote table are: ", (join ", ", @{$p{remote_cols}}); + + if ($p{local_table} eq 'dogs' && @{$p{local_cols}} == 1 && $p{local_cols}[0] eq 'name') { + $p{attrs}{could_be_snoopy} = 1; + + reutrn $p{attrs}; + } + }, =head2 debug