I have a related issue, which actually started this question.

I'm trying to copy column data from one row to another, or in Handel
speak: from the Cart Item to the Order Item.

If both the order item and cart item use the traditionl
inflate_column/inflate/deflate, everything works just fine.

If the order item and cart item instead load InflateColumn::DateTime,
all hell breaks loose. If I try copying the raw value, which is a
DateTime object, I get this what trying to add to a relation:

> Can't use string ("Handel::Subclassing::OrderSchema") as a HASH ref while 
> "strict refs" in use at F:\CatInABox\extlib/DB
> Ix/Class/AccessorGroup.pm line 248.

If I force the copy to eval as a string, I get this error instead:

> Invalid date format: 2006-06-07T00:00:00 at 
> F:\CatInABox\extlib/DBIx/Class/InflateColumn/DateTime.pm line 57
>         DBIx::Class::InflateColumn::DateTime::__ANON__('2006-06-07T00:00:00', 
> 'Handel::Subclassing::OrderSchema::AC700D8
> 21DD111B2BB2DBBA9723...') called at 
> F:\CatInABox\extlib/DBIx/Class/InflateColumn.pm line 83
>         
> DBIx::Class::InflateColumn::_inflated_column('Handel::Subclassing::OrderSchema::AC700D821DD111B2BB2DBBA9723...',
>  'ctime', '2006-06-07T00:00:00') called at 
> F:\CatInABox\extlib/DBIx/Class/InflateColumn.pm line 115
>         
> DBIx::Class::InflateColumn::get_inflated_column('Handel::Subclassing::OrderSchema::AC700D821DD111B2BB2DBBA9723..
> .', 'ctime') called at F:\CatInABox\extlib/DBIx/Class/AccessorGroup.pm line 
> 158
>         
> DBIx::Class::AccessorGroup::__ANON__('Handel::Subclassing::OrderSchema::AC700D821DD111B2BB2DBBA9723...')
>  called
> at t/01datetime.t line 60

Again, this is only when I load InflateColumn::DateTime. Manually
calling inflate_column with inflate/deflates works just fine, even
though in the end, I'm just copying DateTime objects in both cases.

Here's the copying code:

> sub copy_cart_items {
>     my ($self, $order, $cart) = @_;
>     my %columns = map {$_ => $_} 
> $order->schema_class->source($order->item_class->schema_source)->columns;
> 
>     foreach my $item ($cart->items) {
>         my %copy;
> 
>         foreach 
> ($cart->item_class->schema_class->source($cart->item_class->schema_source)->columns)
>  {
>             next if $_ =~ /^(id|cart)$/i;
>             next unless (exists $columns{$_});
> 
>             $copy{$_} = $item->storage->$_;
>         };
> 
>         $copy{'id'} = $self->uuid unless 
> Handel::Constraints::constraint_uuid($copy{'id'});
>         $copy{'orderid'} = $order->id;
>         $copy{'total'} = $copy{'quantity'}*$copy{'price'};
> 
>         $order->storage->create_related($order->item_relationship, \%copy);
>       # error get's thrown in line above
>       # ->storage is the resultset result / schema item
>     };
> };


Here's the item classes:

> # $Id: Item.pm 1157 2006-05-19 22:00:35Z claco $
> package Handel::Subclassing::Schema::CartItem;
> use strict;
> use warnings;
> use base qw/DBIx::Class/;
> use Handel::Currency;
> use DateTime::Format::MySQL;
> 
> __PACKAGE__->load_components(qw/UUIDColumns InflateColumn::DateTime Core/);
> __PACKAGE__->table('cart_items');
> __PACKAGE__->source_name('CartItem');
> __PACKAGE__->add_columns(qw/id cart sku quantity price description/);
> __PACKAGE__->add_column(ctime => {data_type => 'datetime'});
> 
> __PACKAGE__->set_primary_key('id');
> __PACKAGE__->uuid_columns('id');
> 
> #__PACKAGE__->inflate_column('price', {
> #    inflate => sub {Handel::Currency->new(@_)},
> #    deflate => sub {shift}
> #});
> 
> #__PACKAGE__->inflate_column('ctime', {
> #     inflate => sub { DateTime::Format::MySQL->parse_datetime(shift); },
> #     deflate => sub { DateTime::Format::MySQL->format_datetime(shift); },
> #});


> # $Id: Item.pm 1178 2006-05-31 01:59:59Z claco $
> package Handel::Subclassing::Schema::OrderItem;
> use strict;
> use warnings;
> use base qw/DBIx::Class/;
> use Handel::Currency;
> use DateTime::Format::MySQL;
> 
> __PACKAGE__->load_components(qw/UUIDColumns InflateColumn::DateTime Core/);
> __PACKAGE__->table('order_items');
> __PACKAGE__->source_name('OrderItem');
> __PACKAGE__->add_columns(qw/id orderid sku quantity price description total/);
> __PACKAGE__->add_column(ctime => {data_type => 'datetime'});
> 
> __PACKAGE__->set_primary_key('id');
> __PACKAGE__->uuid_columns('id');
> __PACKAGE__->inflate_column('price', {
>     inflate => sub {Handel::Currency->new(@_)},
>     deflate => sub {shift}
> });
> 
> #__PACKAGE__->inflate_column('total', {
> #    inflate => sub {Handel::Currency->new(@_)},
> #    deflate => sub {shift}
> #});
> 
> #__PACKAGE__->inflate_column('ctime', {
> #     inflate => sub { DateTime::Format::MySQL->parse_datetime(shift); },
> #     deflate => sub { DateTime::Format::MySQL->format_datetime(shift); },
> #});
> 
> 1;


Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/

Reply via email to