attribute
- Fix ambiguity in default directory handling of create_ddl_dir
(RT#54063)
+ - Support add_columns('+colname' => { ... }) to augment column
+ definitions.
0.08120 2010-02-24 08:58:00 (UTC)
- Make sure possibly overwritten deployment_statements methods in
groditi: Guillermo Roditi <groditi@cpan.org>
+hobbs: Andrew Rodland <arodland@cpan.org>
+
ilmari: Dagfinn Ilmari MannsE<aring>ker <ilmari@ilmari.org>
jasonmay: Jason May <jason.a.may@gmail.com>
L<DBIx::Class::Row> objects. You can change the name of the accessor
by supplying an L</accessor> in the column_info hash.
+If a column name beginning with a plus sign ('+col1') is provided, the
+attributes provided will be merged with any existing attributes for the
+column, with the new attributes taking precedence in the case that an
+attribute already exists. Using this without a hashref
+(C<< $source->add_columns(qw/+col1 +col2/) >>) is legal, but useless --
+it does the same thing it would do without the plus.
+
The contents of the column_info are not set in stone. The following
keys are currently recognised/used by DBIx::Class:
my @added;
my $columns = $self->_columns;
while (my $col = shift @cols) {
+ my $column_info = {};
+ if ($col =~ s/^\+//) {
+ $column_info = $self->column_info($col);
+ }
+
# If next entry is { ... } use that for the column info, if not
# use an empty hashref
- my $column_info = ref $cols[0] ? shift(@cols) : {};
+ if (ref $cols[0]) {
+ my $new_info = shift(@cols);
+ %$column_info = (%$column_info, %$new_info);
+ }
push(@added, $col) unless exists $columns->{$col};
$columns->{$col} = $column_info;
}
my $source = $class->result_source_instance;
$source->add_columns(@cols);
foreach my $c (grep { !ref } @cols) {
+ # If this is an augment definition get the real colname.
+ $c =~ s/^\+//;
+
$class->register_column($c => $source->column_info($c));
}
}
starts_at => { data_type => 'date' },
created_on => { data_type => 'timestamp' },
- varchar_date => { data_type => 'varchar', inflate_date => 1, size => 20, is_nullable => 1 },
- varchar_datetime => { data_type => 'varchar', inflate_datetime => 1, size => 20, is_nullable => 1 },
+ varchar_date => { data_type => 'varchar', size => 20, is_nullable => 1 },
+ varchar_datetime => { data_type => 'varchar', size => 20, is_nullable => 1 },
skip_inflation => { data_type => 'datetime', inflate_datetime => 0, is_nullable => 1 },
ts_without_tz => { data_type => 'datetime', is_nullable => 1 }, # used in EventTZPg
);
__PACKAGE__->set_primary_key('id');
+# Test add_columns '+colname' to augment a column definition.
+__PACKAGE__->add_columns(
+ '+varchar_date' => {
+ inflate_date => 1,
+ },
+ '+varchar_datetime' => {
+ inflate_datetime => 1,
+ },
+);
+
1;