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

Lyle Kopnicky lwk at rentrak.com
Tue Sep 13 19:46:19 GMT 2011


Thanks for your help.

On Mon, Sep 12, 2011 at 6:06 PM, neil.lunn <neil at mylunn.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/=
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?

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110913/b83=
407c7/attachment.htm


More information about the DBIx-Class mailing list