[Dbix-class] Next problem with 0.8126 , many-to-many an +colums

Peter Rabbitson rabbit+dbic at rabbit.us
Tue Jan 18 00:00:31 GMT 2011


Rolf Schaufelberger wrote:
> I've found another  issue where the update breaks old code:
> 
> Given the following definitions:
> 
> package PW::Iprinter::DB::Article;
> __PACKAGE__->many_to_many ( children  => 'article_children', 'child' );
> 
> The following statement gives an error:
> 
> my @article = $proto->children ({article_group_id => 1009, active=>1}, 
>                        {order_by=>'sort', '+columns' => ['me.mode'] }); 
> 
> ($proto is a  PW::Iprinter::DB::Article )
> 

Sorry for not reading your email more carefully last time. Your code was
relying on a bug that was fixed in 0.08125 [1]. When +columns was written
originally, for some reason a
  +columns => ['foo.bar']
decomposed to
  +select => 'foo.bar'  /  +as => 'bar'

whereas a
  columns => ['foo.bar']
would properly decompose to
  select => 'foo.bar'  /  as => 'foo.bar'

So in your case now you are saying "make me children articles, and hang
the value of 'me.code' off each article as a related 'me' object. Hence
you receiving a "no such relationship" exception. Just to clarify your
statement above is equivalent to (as can be seen here [2]):

  my @article =

  # At the end of this line there is one table, aliased as 'me' with the
  # fk values from $proto already filled in (this is how $obj->rel works)
  # The resultset returns objects of the ::DB::ArticleArticle class
  $proto->related_resultset('article_children')

  # At the end of this line we have a real join, with the left side
  # still aliased to 'me', and the right side aliased to 'child'
  # (this is how $rs->search_related($rel) works)
  # The resultset returns objects of the ::DB::Article class
  ->related_resultset('child')

  # Here we apply the conditions/attributes
  ->search(
    {article_group_id => 1009, active=>1},
    {order_by=>'sort', '+columns' => ['me.mode'] }
  )

And the instruction of +as => 'me.mode' asks for
$db_article_rs->result_source->relationship_info('me')
which in turn throws up.

Since you were relying on a bug I am afraid you will need to fix your
code. A +columns => [ { 'mode' => 'me.mode' } ] will yield behavior
identical to the old broken +columns. Whether this is what you really
want is an exercise to the reader :)

Cheers!

[1] http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=blob;f=Changes;h=18ed5958a80ffddada628fe73f5de0f1bd9e489f;hb=HEAD#l51
[2] http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=blob;f=lib/DBIx/Class/Relationship/ManyToMany.pm;h=0b4ad56dd7710a0fad8e706d25168d0bdf7f33a1;hb=HEAD#l67



More information about the DBIx-Class mailing list