From: Peter Rabbitson Date: Wed, 24 Mar 2010 10:27:36 +0000 (+0000) Subject: A better illustration how to add relationships at runtime X-Git-Tag: v0.08121~43 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c8fa76fc78f684e484b4753165601b59eb51b1f9;p=dbsrgits%2FDBIx-Class.git A better illustration how to add relationships at runtime --- diff --git a/maint/joint_deps.pl b/maint/joint_deps.pl index cfdbede..35ef99e 100755 --- a/maint/joint_deps.pl +++ b/maint/joint_deps.pl @@ -19,15 +19,27 @@ use Data::Dumper::Concise; my $s = CPANDB::Schema->connect (sub { CPANDB->dbh } ); # reference names are unstable - just create rels manually -# is there a saner way to do that? -my $distclass = $s->class('Distribution'); -$distclass->has_many ( +my $distrsrc = $s->source('Distribution'); + +# the has_many helper is a class-only method (why?), thus +# manual add_rel +$distrsrc->add_relationship ( 'deps', $s->class('Dependency'), - 'distribution', + { 'foreign.distribution' => 'self.' . ($distrsrc->primary_columns)[0] }, + { accessor => 'multi', join_type => 'left' }, ); -$s->unregister_source ('Distribution'); -$s->register_class ('Distribution', $distclass); + +# here is how one could use the helper currently: +# +#my $distresult = $s->class('Distribution'); +#$distresult->has_many ( +# 'deps', +# $s->class('Dependency'), +# 'distribution', +#); +#$s->unregister_source ('Distribution'); +#$s->register_class ('Distribution', $distresult); # a proof of concept how to find out who uses us *AND* SQLT