[Dbix-class] add_columns: source or class?

Christopher H. Laco claco at chrislaco.com
Mon Jul 3 15:12:46 CEST 2006


>> $ENV{DBIX_CLASS_STORAGE_DBI_DEBUG} = 1;
>> use Handel::Cart::Schema;
>> my $schema = Handel::Cart::Schema->connect;
>>
>> $schema->source('Carts')->add_column('custom');
>> print $schema->source('Carts')->columns, "\n";
>>
>> print $schema->resultset('Carts')->search({custom => 1});
>>
>> my $new = $schema->resultset('Carts')->create({
>>    id => 1, custom => 'foo'
>> });
> 
> with the error on create. Note, search succeeds, and contains the added
> column in line 2:
> 
>> idshoppertypenamedescriptioncustom
>> SELECT me.id, me.shopper, me.type, me.name, me.description, me.custom FROM cart me WHERE ( custom = ? ): '1'
>> DBIx::Class::ResultSet::create(): No such column custom on Handel::Schema::Cart at test.pl line 21

Just to add to the mess, it appears that the accessor for the added
column is not created either:

> $ENV{DBIX_CLASS_STORAGE_DBI_DEBUG} = 1;
>     
> use Handel::Cart::Schema;
> my $schema = Handel::Cart::Schema->connect;
> 
> $schema->source('Carts')->add_columns('custom');
> print $schema->source('Carts')->columns, "\n";
> 
> print $schema->resultset('Carts')->search({custom => 1});
> 
> my $new = $schema->resultset('Carts')->create({
>    id => 3 # custom data removed to get a create to work
> });
> 
> my $cart = $schema->resultset('Carts')->find(3);
> 
> print $cart->custom;

yields:

> idshoppertypenamedescriptioncustom
> SELECT me.id, me.shopper, me.type, me.name, me.description, me.custom FROM cart me WHERE ( custom = ? ): '1'
> INSERT INTO cart (id) VALUES (?): '3'
> SELECT me.id, me.shopper, me.type, me.name, me.description, me.custom FROM cart me WHERE ( ( me.id = ? ) ): '3'
> Can't locate object method "custom" via package "Handel::Schema::Cart" at test.pl line 27.


So, this is a matter of class vs. source.
I thought almost all methoeds called on $schema->class were proxied back
into its $schema->source. IF the two are seperate, then I'm wondering
what the point of add_columns is on a source, if the column, and it's
accessor don't make it into the class.

-=Chris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060703/4fc618e5/attachment.pgp 


More information about the Dbix-class mailing list