[Dbix-class] compoase_namespace, add_column, and result_source_instance
Christopher H. Laco
claco at chrislaco.com
Sat Jul 8 16:03:41 CEST 2006
Just to expand the example, resetting class->result_source_instance to
use the source from the new schema instead of the original schema
appears to fix the problem:
> use Handel::Cart::Schema;
>
> my $schema = Handel::Cart::Schema->connect($ENV{HandelDBIDSN});
> my $new = $schema->compose_namespace('Foo');
>
> print $schema->class('Items'), "\n";
> print $new->class('Items'), "\n";
>
> print $schema->class('Items')->result_source_instance, "\n";
> print $new->class('Items')->result_source_instance, "\n";
>
> print $schema->source('Items'), "\n";
> print $new->source('Items'), "\n";
>
>
> # this ishacky, but it appears to work...
> $new->class('Items')->result_source_instance($new->source('Items'));
> $new->source('Items')->add_column('custom' => {accessor => 'foo'});
> $new->class('Items')->register_column('custom' => {accessor => 'foo'});
>
> print $new->class('Items')->columns, "\n";
> print $schema->class('Items')->columns, "\n";
> print $new->class('Items')->columns, "\n";
> print $schema->class('Items')->columns, "\n";
>
> $new->resultset('Items')->delete_all;
> $new->resultset('Items')->create({id=>1, custom=>'foo'});
> print $new->resultset('Items')->find(1)->bar;
At this point, everything prints the right amount of columns, and the
accessor is created in the correct source class.
One more item of interest...if I try this instead:
> # this ishacky, but it appears to work...
> $new->class('Items')->result_source_instance($new->source('Items'));
> $new->source('Items')->add_column('custom' => {accessor => 'foo'});
> $new->class('Items')->register_column('custom' => $new->source('Items')->column_info('custom'));
I get this:
> Attempt to free unreferenced scalar: SV 0x250793c at F:\CatInABox\extlib/SQL/Abstract/Limit.pm line 325.
> Attempt to free unreferenced scalar: SV 0x25124bc at F:\CatInABox\extlib/SQL/Abstract/Limit.pm line 325.
So, at this point, I think I can work around the nuances. I'm just not
sure if anything in there related to result_source_instance after
compose_namespace is a bug or a feature.
-=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/20060708/1ce4d798/attachment.pgp
More information about the Dbix-class
mailing list