Am 2011-09-13 21:46, schrieb Lyle Kopnicky:
Thanks for your help.

On Mon, Sep 12, 2011 at 6:06 PM, neil.lunn 
<[email protected]<mailto:[email protected]>> wrote:

Was there some reason that this was not good enough for your purposes:
http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Cookbook.pod#Creating_DDL_SQL<http://search.cpan.org/%7Eabraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Cookbook.pod#Creating_DDL_SQL>

I guess what I didn't make clear is that the DDL is for creating temporary 
tables and views and shuttling data around within a transaction (this is with 
PostgreSQL). So I don't need to spit it out to a file, just run it on the dbh 
that belongs to this schema. The DDL isn't really that complex, I guess. 
Generating it is tricky, and based upon schema reflection, but I already have 
code that can do it by calling methods on the Result class.

If you really need something more complex than that then you need to be looking 
at the ResultSource objects rather than the ResultSet. Or use them direct as I 
really don't think you need an active connection to do this, unless you are 
trying to do some sort of schema deploy on connect.

Yes, I do need to install this DDL live.

The problem is that if I define extra methods on my Result class:

package My::Schema::Result::MyTable;

... table definition auto-generated by DBIx::Class::Loader ...

sub foo { ... }

1;

use My::Schema;
My::Schema->resultsource('MyTable')->foo(...);

I get an error that foo is not defined on DBIx::Class::ResultSource. It's not 
clear from the DBIx::Class documentation when My::Schema::Result::MyTable would 
get instantiated... I think perhaps as a Row?
Because the method foo is a method of the result (row) class and not the 
resultsource class.
If you want to add resultsource methods you need to write a ResultSource::Table 
(or ::View) subclass and assign it to your result class:
__PACKAGE__->table_class('Your::Model::ResultSource::WithFooMethod');

basically

use My::Schema::Result::MyTable;
print My::Schema::Result::MyTable->table();

or any other accessor that is valid for the ResultSource is always going to 
work in any way you basically do that.

Yep, I can do that, by directly importing My::Schema::Result::MyTable. But the 
problem is that it's not connected to a dbh, so it can't execute DDL.

- Lyle



_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to