[Dbix-class] 0.08 Regression?

Christopher H. Laco claco at chrislaco.com
Wed Jun 13 17:51:38 GMT 2007


Adam Herzog wrote:
> I think I stumbled across a regression while testing RC3. I'm not sure
> how best to incorporate a test into the suite, but I've put together a
> minimal case that demonstrates the problem. It works correctly (or at
> least, as I expect it to) under 0.07006, but not the latest RC.
> =

> The test scenario contains authors and books, where a book belongs_to an
> author, and an author has_many books. The problem seems to occur where
> the foreign key in books has an accessor set, and the relationship has
> the same name as the actual column name. Somewhere along the line, the
> column accessor is getting confused with the relationship, I guess.
> =

> I've included the test files inline below, as well as attached them to
> the email.
> =

> -A

Changeset 3358: "%colinfo accessors and inflate_column now work together"

I did this one myself. Basically, inflated columns weren't getting set
to their accessors [instead of colname].

Since relationships are really inflators, I'd say this is the source of
the change. I could be wrong.


Normally, ->author() would return the author field id value. But since
you've asked it to return an author object via belongs_tom ->author()
would return the author object.

Then, you told DBIC to change the accessor from author() to author_id().
So, author_id() returns the same object that ->author() would have
because of the belongs_to.

Let's forget about the accessor option for a moment. Once belongs_to is
in place, you would always get an author object, never the field value
itself.

Seems like the correct behavior to me.

-=3DChris

> =

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> MyDB.pm
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> =

> package MyDB;
> use strict;
> use warnings;
> =

> use base qw/DBIx::Class::Schema/;
> =

> __PACKAGE__->load_classes(qw/Author Book/);
> =

> 1;
> =

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> MyDB/Author.pm
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> =

> package MyDB::Author;
> use warnings;
> use strict;
> =

> use base qw/DBIx::Class/;
> =

> __PACKAGE__->load_components(qw/ Core /);
> =

> __PACKAGE__->table('authors');
> =

> __PACKAGE__->add_columns(
>     id =3D> {
>         data_type         =3D> 'INTEGER',
>         is_nullable       =3D> 0,
>         is_auto_increment =3D> 1,
>     },
>     name =3D> {
>         data_type   =3D> 'VARCHAR',
>         size        =3D> 150,
>         is_nullable =3D> 0,
>     },
> );
> =

> __PACKAGE__->set_primary_key('id');
> =

> __PACKAGE__->has_many( 'books' =3D> 'MyDB::Book', 'author' );
> =

> 1;
> =

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> MyDB/Book.pm
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> =

> package MyDB::Book;
> use warnings;
> use strict;
> =

> use base qw/DBIx::Class/;
> =

> __PACKAGE__->load_components(qw/ Core /);
> =

> __PACKAGE__->table('books');
> =

> __PACKAGE__->add_columns(
>     id =3D> {
>         data_type         =3D> 'INTEGER',
>         is_nullable       =3D> 0,
>         is_auto_increment =3D> 1,
>     },
>     title =3D> {
>         data_type   =3D> 'VARCHAR',
>         size        =3D> 150,
>         is_nullable =3D> 0,
>     },
>     author =3D> {
>         accessor       =3D> 'author_id',
>         data_type      =3D> 'INTEGER',
>         is_nullable    =3D> 0,
>         is_foreign_key =3D> 1,
>     },
> );
> =

> __PACKAGE__->set_primary_key('id');
> =

> __PACKAGE__->belongs_to( 'author' =3D> 'MyDB::Author', 'author' );
> =

> 1;
> =

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> test.t
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> =

> use strict;
> use warnings;
> use Test::More tests =3D> 3;
> =

> use MyDB;
> my $schema =3D MyDB->connect( 'dbi:mysql:test', '', '' );
> =

> $schema->deploy( { add_drop_table =3D> 1 } );
> $schema->populate( 'Author', [ [qw/id name/], [ 1, 'Stephen King' ], ] );
> $schema->populate( 'Book', [ [qw/id title author/], [ 1, 'Misery', 1 ],
> ] );
> =

> my $book =3D $schema->resultset('Book')->find(1);
> =

> is( $book->title(),        'Misery' );
> is( $book->author_id(),    1 );
> is( $book->author->name(), 'Stephen King' );
> =

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> test output (under RC3)
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> test....ok 1/3
> #   Failed test at test.t line 15.
> #          got: 'MyDB::Author=3DHASH(0x1a9bbbc)'
> #     expected: '1'
> Can't locate object method "author" via package "MyDB::Book" at test.t
> line 16.
> test....NOK 2/3# Looks like you planned 3 tests but only ran 2.
> # Looks like you failed 1 test of 2 run.
> # Looks like your test died just after 2.
> test....dubious
>         Test returned status 255 (wstat 65280, 0xff00)
> DIED. FAILED tests 2-3
>         Failed 2/3 tests, 33.33% okay
> Failed Test Stat Wstat Total Fail  List of Failed
> -------------------------------------------------------------------------=
------
> =

> test.t       255 65280     3    3  2-3
> Failed 1/1 test scripts. 2/3 subtests failed.
> Files=3D1, Tests=3D3,  0 wallclock secs ( 0.33 cusr +  0.06 csys =3D  0.3=
9 CPU)
> Failed 1/1 test programs. 2/3 subtests failed.
> =

> =

> =

> ------------------------------------------------------------------------
> =

> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.=
org/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070613/41=
c7e386/signature.pgp


More information about the Dbix-class mailing list