[Dbix-class] Can add_column be called on a Row?

Peter Rabbitson rabbit+dbic at rabbit.us
Sat Oct 4 19:04:32 GMT 2014


On 09/30/2014 05:00 PM, Bill Moseley wrote:
> I'm upgrading DBIC on a project and it's helping to find bugs in our code.
>
> Running tests I found an error ("No such column 'last_saved') and then
> found this code:
>
>
>      my $last_saved_column_data = {
>          data_type     => 'timestamp with time zone',
>          default_value => 'now()',
>          is_nullable   => 1,
>          size          => 8,
>      };
>
>      foreach ( $users_rs->all ) {
>
>          $_->add_column( 'last_saved' => $last_saved_column_data );
>          $_->set_column( 'last_saved' => $column_value );
>      }
>
> I assume what the programmer wanted to do there was just add an
> attribute "last_saved" to the Users result class.   Or maybe only to
> those specific rows returned in that resultset (e.g. as a singleton
> method
> <http://search.cpan.org/dist/MooseX-SingletonMethod/lib/MooseX/SingletonMethod.pm>).
>
> Apparently that was working in the past.   Was that ever a supported
> behavior?

Not exactly. I think what is biting you is the following: 
https://github.com/dbsrgits/dbix-class/commit/4006691d207
In particular note that this diff was necessary before this change could 
be instituted: 
https://github.com/dbsrgits/dbix-class/commit/12b348d93#diff-151aa4502496ea8360920506d46ce4bdL35

The problem in its core (and this has always been the case) is that:
   My::App::Schema::Result::Foo->result_source_instance
     !=
   My::App::Schema->source('Foo')
     !=
   $my_app_schema_instance->source('Foo')

The change in 4006691d207 makes things consistently work on the "current 
instance level", whereas before it was not entirely clear where the 
ResultSourceProxy call will actually land.

Does this answer your question? Is there something I missed when 
implementing this part?



More information about the DBIx-Class mailing list