[Dbix-class] Re: Get table name from ResultSet class?

Alexander Hartmaier alexander.hartmaier at t-systems.at
Wed Sep 14 18:28:52 GMT 2011


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

On Mon, Sep 12, 2011 at 6:06 PM, neil.lunn <neil at mylunn.id.au<mailto:neil at m=
ylunn.id.au>> 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/Co=
okbook.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 wi=
th PostgreSQL). So I don't need to spit it out to a file, just run it on th=
e dbh that belongs to this schema. The DDL isn't really that complex, I gue=
ss. Generating it is tricky, and based upon schema reflection, but I alread=
y 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 loo=
king at the ResultSource objects rather than the ResultSet. Or use them dir=
ect as I really don't think you need an active connection to do this, unles=
s 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 n=
ot clear from the DBIx::Class documentation when My::Schema::Result::MyTabl=
e would get instantiated... I think perhaps as a Row?
Because the method foo is a method of the result (row) class and not the re=
sultsource class.
If you want to add resultsource methods you need to write a ResultSource::T=
able (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/dbix-class@lists.scsys.co=
.uk

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
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 pr=
ivileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110914/48d=
be22b/attachment.htm


More information about the DBIx-Class mailing list