X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=31221e6392830d7495c86e670835f9812778f278;hb=4a6249b20462d8b7ff041a29473bf5e13cf2fe6c;hp=c93d28d887edeb69351212b0dec1069f6cbe969e;hpb=c34033b1f21ade200b20f78940c2c32a8843fd17;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 c93d28d..31221e6 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -29,7 +29,7 @@ use List::MoreUtils qw/all any firstidx uniq/; use File::Temp 'tempfile'; use namespace::clean; -our $VERSION = '0.07032'; +our $VERSION = '0.07035'; __PACKAGE__->mk_group_ro_accessors('simple', qw/ schema @@ -389,17 +389,20 @@ override the introspected attributes of the foreign key if any. For example: relationship_attrs => { - has_many => { cascade_delete => 1, cascade_copy => 1 }, + has_many => { cascade_delete => 1, cascade_copy => 1 }, + might_have => { cascade_delete => 1, cascade_copy => 1 }, }, use this to turn L cascades to on on your -L relationships, they default to -off. +L and +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: +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 @@ -416,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; @@ -430,6 +434,50 @@ For example: } }, +These are the default attributes: + + has_many => { + cascade_delete => 0, + cascade_copy => 0, + }, + might_have => { + cascade_delete => 0, + cascade_copy => 0, + }, + belongs_to => { + on_delete => 'CASCADE', + on_update => 'CASCADE', + is_deferrable => 1, + }, + +For L relationships, these +defaults are overridden by the attributes introspected from the foreign key in +the database, if this information is available (and the driver is capable of +retrieving it.) + +This information overrides the defaults mentioned above, and is then itself +overridden by the user's L for C if any are +specified. + +In general, for most databases, for a plain foreign key with no rules, the +values for a L relationship +will be: + + on_delete => 'NO ACTION', + on_update => 'NO ACTION', + is_deferrable => 0, + +In the cases where an attribute is not supported by the DB, a value matching +the actual behavior is used, for example Oracle does not support C +rules, so C is set to C. This is done so that the +behavior of the schema is preserved when cross deploying to a different RDBMS +such as SQLite for testing. + +In the cases where the DB does not support C foreign keys, the +value is set to C<1> if L has a working C<< +$storage->with_deferred_fk_checks >>. This is done so that the same +L code can be used, and cross deployed from and to such databases. + =head2 debug If set to true, each constructive L statement the loader @@ -570,6 +618,10 @@ If it is a coderef, the argument passed will be a hashref of this form: remote_class => name of the DBIC class we are related to, remote_moniker => moniker of the DBIC class we are related to, remote_columns => columns in the other table in the relationship, + # for type => "many_to_many" only: + link_class => name of the DBIC class for the link table + link_moniker => moniker of the DBIC class for the link table + link_rel_name => name of the relationship to the link table } DBICSL will try to use the value returned as the relationship name.