Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnColumnMissing breaks create with related objects #93

Open
andrewgregory opened this issue Oct 10, 2018 · 0 comments
Open

OnColumnMissing breaks create with related objects #93

andrewgregory opened this issue Oct 10, 2018 · 0 comments

Comments

@andrewgregory
Copy link

#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

my $schema = TestSchema->connect('dbi:SQLite:dbname=:memory:');
$schema->deploy;
my $rs = $schema->resultset('Foo');

# breaks Helper::Row::OnColumnMissing
ok( eval { $rs->create( { id => 1, bar => [ { id => 1 } ] } ); 1; } );
is "$@", '';
is( $rs->find( { id => 1 } )->bar->count, 1 );

done_testing;

BEGIN {
    package TestSchema::Bar;
    use parent 'DBIx::Class::Core';

    # breaks creating related Bar from Foo
    __PACKAGE__->load_components('Helper::Row::OnColumnMissing');
    sub on_column_missing {'die' }

    __PACKAGE__->table('bar');
    __PACKAGE__->add_columns(
        id     => { data_type => 'integer' },
        foo_id => { data_type => 'integer' },
    );
    __PACKAGE__->set_primary_key('id');

    package TestSchema::Foo;
    use parent 'DBIx::Class::Core';
    __PACKAGE__->table('foo');
    __PACKAGE__->add_columns( id => { data_type => 'integer' }, );
    __PACKAGE__->set_primary_key('id');

    package TestSchema;
    use parent 'DBIx::Class::Schema';
    # create relationships after results are fully defined
    TestSchema::Bar->belongs_to( foo => 'TestSchema::Foo', 'foo_id' );
    TestSchema::Foo->has_many( bar => 'TestSchema::Bar', 'foo_id' );
    __PACKAGE__->register_class( Foo => __PACKAGE__ . '::Foo' );
    __PACKAGE__->register_class( Bar => __PACKAGE__ . '::Bar' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant