#!/usr/bin/perl
use strict;
package My::Schema::Table1;
use base qw(DBIx::Class);
__PACKAGE__->load_components(qw(PK UTF8Columns Core));
__PACKAGE__->table('table1');
__PACKAGE__->add_columns(qw(id text1));
__PACKAGE__->utf8_columns(qw(text1));
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_one(table2 => 'My::Schema::Table2', 'table1_id');
package My::Schema::Table2;
use base qw(DBIx::Class);
__PACKAGE__->load_components(qw(PK UTF8Columns Core));
__PACKAGE__->table('table2');
__PACKAGE__->add_columns(qw(id table1_id text2));
__PACKAGE__->utf8_columns(qw(text2));
__PACKAGE__->set_primary_key('id');
__PACKAGE__->belongs_to(table1 => 'My::Schema::Table1', 'table1_id');
package My::Schema;
use base qw(DBIx::Class::Schema);
__PACKAGE__->load_classes(qw(Table1 Table2));
package main;
binmode(STDOUT, ':utf8');
my $schema = My::Schema->connect('dbi:SQLite:dbname=:memory:');
$schema->storage->dbh->do(<<'EOF');
create table table1 (
id integer primary key,
text1 text
)
EOF
$schema->storage->dbh->do(<<'EOF');
create table table2 (
id integer primary key,
table1_id integer references table1,
text2 text
)
EOF
my $unicode = "\x{201c}hello\x{201d}";
my $rs1 = $schema->resultset('Table1');
my $rs2 = $schema->resultset('Table2');
$rs1->create({
id => 1,
text1 => $unicode,
table2 => {
id => 2,
text2 => $unicode,
},
});
# works
print($rs1->first()->table2()->text2(), "\n");
my $row = $rs1->search(undef, {
join => 'table2',
select => [ qw(text1 text2) ],
})->first();
# works
print($row->get_column('text1'), "\n");
# does not work
print($row->get_column('text2'), "\n");
$row = $rs1->search(undef, {
select => [ qw(text1) ],
as => [ qw(text) ],
})->first();
# does not work
print($row->get_column('text'), "\n");