[Dbix-class] Schema::Loader and views on Pg

Dorian Taylor (Lists) dorian.taylor.lists at gmail.com
Mon May 3 04:56:15 GMT 2010

On 2-May-10, at 12:59 PM, Matt S Trout wrote:
> Welcome back.


> What about letting S::L pull the column names and then just setting  
> the
> primary keys and adding rels as a fixup?

I think what I'm going to do is make the current views into tables and  
then use triggers on the database (probably rules actually, then I  
don't have to go faffing around with plsql) to append to the logs when  
I update. That'll probably perform better in the long run anyway.

In that case, is there a "read-only" base class kicking around to make  
it easier to diagnose errant updates (e.g. by croaking when you try to  
use a mutator instead of waiting for the database to reject it with an  

> Note that once you've got $other_class loaded you can always do
> my $source = My::Schema::Foo->result_source_instance;
> and then pull the relationships straight out of the main foo source.
> See the code in
> git://git.shadowcat.co.uk/dbsrights/DBIx-Class-ResultSource- 
> MultipleTableInheritance.git
> for some interesting Pg madness with views and result source  
> introspection
> (also, mad props to Amiri Barksdale for documenting the thing for me  
> - just
> waiting for a couple more people to say "yes it works" and I'll see  
> about
> shipping it to CPAN)

Tempting, but probably opening a can of worms with versions/deployment  
etc. Would prefer to stick to CPAN.

> It only ever sort of worked. In fact, IME it only worked reliably if  
> you
> were me (or at least wrote all your add_relationship calls by hand  
> with
> explicit join conditions).
> After trying about ten different ways to fix it and realising that  
> very
> few people used the thing at all, I ripped it out sideways on the  
> grounds
> that "never works" was overall less annoying than "mostly works  
> except you
> get half way through a project and hit a bug and get an  
> incomprehensible
> error message".


> Also, aliased.pm can pretty much eliminate the extra typing just as  
> well :)

Yes, that looks like it would work.

Hmm, is there a way to get Schema::Loader to append arbitrary code to  
a selection of the files it generates? like

make_schema_at(append_code => sub {
     my $table = shift;
     return unless $TABLES{$table};
     my $code = generate_extra_code_for($table);
     return $code;
  }); ?


Dorian Taylor

More information about the DBIx-Class mailing list