From: Amiri Barksdale at Home Date: Mon, 7 Mar 2011 14:53:46 +0000 (-0800) Subject: Experiment with sequence. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5fa55fff260e2cc82bc4198b9b7d85b3dcd7d83d;p=dbsrgits%2FDBIx-Class-ResultSource-MultipleTableInheritance.git Experiment with sequence. --- diff --git a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm index ea14a3d..805f843 100644 --- a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm +++ b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm @@ -4,6 +4,7 @@ use strict; use warnings; use parent qw(DBIx::Class::ResultSource::View); use Method::Signatures::Simple; +use Carp::Always; use Carp::Clan qw/^DBIx::Class/; use aliased 'DBIx::Class::ResultSource::Table'; use aliased 'DBIx::Class::ResultClass::HashRefInflator'; @@ -19,7 +20,7 @@ __PACKAGE__->mk_group_accessors(simple => qw(parent_source additional_parents)); # # On construction, we hook $self->result_class->result_source_instance # if present to get the superclass' source object -# +# # When attached to a schema, we need to add sources to that schema with # appropriate relationships for the foreign keys so the concrete tables # get generated @@ -83,7 +84,7 @@ method add_additional_parent ($source) { method _source_by_name ($name) { my $schema = $self->schema; - my ($source) = + my ($source) = grep { $_->name eq $name } map $schema->source($_), $schema->sources; confess "Couldn't find attached source for parent $name - did you use load_classes? This module is only compatible with load_namespaces" @@ -103,7 +104,6 @@ method schema (@args) { @{$self->additional_parents||[]} ]); } - use Devel::Dwarn; use 5.012; say Dwarn $ret; return $ret; } @@ -120,7 +120,7 @@ method attach_additional_sources () { my $parent; if ($self->parent_source) { my $parent_name = $self->parent_source->name; - ($parent) = + ($parent) = grep { $_->name eq $parent_name } map $schema->source($_), $schema->sources; confess "Couldn't find attached source for parent $parent_name - did you use load_classes? This module is only compatible with load_namespaces" @@ -162,20 +162,20 @@ method attach_additional_sources () { $self->columns ); $table->set_primary_key($self->primary_columns); - + ## Attempting to re-add sequence here -- AKB - for my $pk ( $self->primary_columns ) { - if ($parent) { - -#use 5.012; use Devel::Dwarn; say Dwarn $schema->source($table->_relationships->{parent}->{class}) if $table->_relationships->{parent}->{class}; - $table->columns_info->{$pk}->{sequence} = - $self->set_sequence( - $schema->source( $table->_relationships->{parent}->{class} )->name, - $self->primary_columns ) - if $table->columns_info->{$pk}->{originally_defined_in} ne $self->name - && $table->_relationships->{parent}->{class}; - } - } + #for my $pk ( $self->primary_columns ) { + #if ($parent) { + +##use 5.012; use Devel::Dwarn; say Dwarn $schema->source($table->_relationships->{parent}->{class}) if $table->_relationships->{parent}->{class}; + #$table->columns_info->{$pk}->{sequence} = + #$self->set_sequence( + #$schema->source( $table->_relationships->{parent}->{class} )->name, + #$self->primary_columns ) + #if $table->columns_info->{$pk}->{originally_defined_in} ne $self->name + #&& $table->_relationships->{parent}->{class}; + #} + #} # we need to copy our rels to the raw object as well # note that ->add_relationship on a source object doesn't create an @@ -204,7 +204,7 @@ method attach_additional_sources () { my $f_source_name = $f_source->${\ ($one_of_us ? 'raw_source_name' : 'source_name') }; - + $table->add_relationship( '_'.$rel, $f_source_name, @{$rel_info}{qw(cond attrs)} ); @@ -463,7 +463,7 @@ __END__ =head1 NAME DBIx::Class::ResultSource::MultipleTableInheritance -Use multiple tables to define your classes +Use multiple tables to define your classes =head1 NOTICE @@ -507,7 +507,7 @@ This only works with PostgreSQL for the moment. 1; } - + ... my $schema = Cafe->connect($dsn,$user,$pass); @@ -534,7 +534,7 @@ In many applications, many classes are subclasses of others. Let's say you have this schema: # Conceptual domain model - + class User { has id, has name, @@ -584,7 +584,7 @@ investor: "name" text not null, "password" text not null ); - + create table "investor" ( "id" integer not null references user("id"), "dollars" integer @@ -593,7 +593,7 @@ investor: So that investor's PK is just an FK to the user. We can clearly see the class hierarchy here, in which investor is a subclass of user. In DBIx::Class applications, this second strategy looks like: - + my $user_rs = $schema->resultset('User'); my $new_user = $user_rs->create( name => $args->{name}, @@ -622,7 +622,7 @@ we could do this: password => $args->{password}, dollars => $args->{dollars}, ); - + And have it Just Work? The user... { @@ -700,7 +700,7 @@ in the schema, e.g., print STDERR map { "$_\n" } MyApp::Schema->sources; - # Coffee + # Coffee # Beverage # Liquid # Sumatra diff --git a/t/01load.t b/t/01load.t index e5163bc..4f1d7cf 100644 --- a/t/01load.t +++ b/t/01load.t @@ -7,6 +7,7 @@ use LoadTest; BEGIN { $ENV{DBIC_TRACE} = 0; } + my $raw_foo = LoadTest->source('Raw::Foo'); is_deeply( [ $raw_foo->columns ], [qw(id a)],