in reply to Re: Class::DBI many to many delete
in thread Class::DBI many to many delete
Ah - and if I doWebR::M::CDBI::DatafileRelationship->has_a(child=>'WebR::M::CDBI:: +Datafile'); WebR::M::CDBI::DatafileRelationship->has_a(parent=>'WebR::M::CDBI: +:Datafile'); WebR::M::CDBI::Datafile->has_many(parents=>['WebR::M::CDBI::Datafi +leRelationship' => 'parent'],'child', { cascade => 'Class::DBI::Cascade::Delete'}); WebR::M::CDBI::Datafile->has_many(children=>['WebR::M::CDBI::Dataf +ileRelationship' => 'child'],'parent', { cascade => 'Class::DBI::Cascade::Delete'} );
then the child datafiles get deleted too. Great! thanks! And, for the has_many relationships where I just want the FK to be nulled, rather than the record deleted:WebR::M::CDBI::DatafileRelationship->has_a(child=>'WebR::M::CDBI:: +Datafile', {cascade=>'Class::DBI::Cascade::Delete'});
package Class::DBI::Cascade::Nullify; use base 'Class::DBI::Cascade::None'; use Data::Dumper; sub cascade { my ($self, $obj) = @_; my $fk =$self->{_rel}->args->{foreign_key}; foreach ($self->foreign_for($obj)){ $_->$fk(undef); $_->update; } } 1;
|
|---|