On 03/30/2016 02:23 PM, Peter Rabbitson wrote:
perl -It/lib -Ilib -MANFANG -MDevel::Dwarn -e '

   # add the special rel
   require DBICTest::Schema::CD;
   DBICTest::Schema::CD->has_many( links_to_non_mst_producers =>
"DBICTest::Schema::CD_to_Producer", sub {
     my $args = shift;
     {
       "$args->{foreign_alias}.cd" => { -ident =>
"$args->{self_alias}.cdid" },
       "$args->{foreign_alias}.producer" => {
         -in => $args->{self_resultsource}
                      ->schema
                       ->resultset("Producer")
                        ->search({ "me.name" => { -not_like => "%Trout%"
} })
                         ->get_column("producerid")
                          ->as_query
       },
     }
   });


   require DBICTest;


   Dwarn [ DBICTest->init_schema->resultset("CD")->search(
     { cdid => 1 },
     {
       result_class => "DBIx::Class::ResultClass::HashRefInflator",
       prefetch => {
         cd_to_producer => "producer",
         links_to_non_mst_producers => "producer",
       }
     }
   )->all ];
'

Forgot to add - this is what the above produces:

[
  {
    artist => 1,
    cd_to_producer => [
      {
        attribute => undef,
        cd => 1,
        producer => {
          name => "Matt S Trout",
          producerid => 1
        }
      },
      {
        attribute => undef,
        cd => 1,
        producer => {
          name => "Bob The Builder",
          producerid => 2
        }
      },
      {
        attribute => undef,
        cd => 1,
        producer => {
          name => "Fred The Phenotype",
          producerid => 3
        }
      }
    ],
    cdid => 1,
    genreid => 1,
    links_to_non_mst_producers => [
      {
        attribute => undef,
        cd => 1,
        producer => {
          name => "Bob The Builder",
          producerid => 2
        }
      },
      {
        attribute => undef,
        cd => 1,
        producer => {
          name => "Fred The Phenotype",
          producerid => 3
        }
      }
    ],
    single_track => undef,
    title => "Spoonful of bees",
    year => 1999
  }
]


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to