(i.e. $result->set_from_related($custom_rel, $foreign_result_object)
- When in a transaction, DBIC::Ordered now seamlesly handles result
objects that went out of sync with the storage (RT#96499)
+ - CDBICompat::columns() now supports adding columns through supplied
+ Class::DBI::Column instances (GH#52)
* Fixes
- Fix Resultset delete/update affecting *THE ENTIRE TABLE* in cases
use strict;
use warnings;
+use Scalar::Util 'blessed';
+use namespace::clean;
+
sub mk_group_accessors {
my ($class, $group, @cols) = @_;
foreach my $col (@cols) {
- my($accessor, $col) = ref $col ? @$col : (undef, $col);
+ my($accessor, $col) = ref $col eq 'ARRAY' ? @$col : (undef, $col);
my($ro_meth, $wo_meth);
- if( defined $accessor and ($accessor ne $col)) {
+ if (defined blessed $col and $col->isa('Class::DBI::Column')) {
+ $ro_meth = $col->accessor;
+ $wo_meth = $col->mutator;
+ }
+ elsif (defined $accessor and ($accessor ne $col)) {
$ro_meth = $wo_meth = $accessor;
}
else {
--- /dev/null
+use strict;
+use warnings;
+
+# Columns in CDBI could be defined as Class::DBI::Column objects rather than
+# or as well as with __PACKAGE__->columns();
+
+use Test::More;
+
+use lib 't/cdbi/testlib';
+use ColumnObject;
+
+ok(ColumnObject->can('db_Main'), 'set_db()');
+is(ColumnObject->__driver, 'SQLite', 'Driver set correctly');
+
+ColumnObject->create({
+ columna => 'Test Data',
+ columnb => 'Test Data 2',
+});
+
+my $column_object = ColumnObject->retrieve(columna => 'Test Data');
+$column_object->columnb_as_write('Test Data Written');
+$column_object->update;
+$column_object = ColumnObject->retrieve(columna => 'Test Data');
+
+is($column_object->columna_as_read => 'Test Data', 'Read column via accessor');
+is($column_object->columna => 'Test Data', 'Real column returns right data');
+is($column_object->columnb => 'Test Data Written', 'ColumnB wrote via mutator');
+
+done_testing;
--- /dev/null
+package # Hide from PAUSE
+ ColumnObject;
+
+use strict;
+use warnings;
+
+use base 'DBIC::Test::SQLite';
+use Class::DBI::Column;
+
+__PACKAGE__->set_table('column_object');
+
+__PACKAGE__->columns( Primary => 'id' );
+__PACKAGE__->columns( All => (
+ 'id',
+ 'columna',
+ 'columnb',
+ Class::DBI::Column->new('columna' => {accessor => 'columna_as_read'}),
+ Class::DBI::Column->new('columnb' => {mutator => 'columnb_as_write'}),
+));
+
+sub create_sql {
+ return qq{
+ id INTEGER PRIMARY KEY,
+ columna VARCHAR(20),
+ columnb VARCHAR(20)
+ }
+}
+
+1;