Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: retrieving primary key from a DBIx::Class package

by pokki (Monk)
on Apr 24, 2013 at 18:30 UTC ( #1030475=note: print w/replies, xml ) Need Help??

in reply to retrieving primary key from a DBIx::Class package

You're almost there.

What you need to do is 1. get your ResultSet's data source, i.e. what it gets the actual data from; in DBIC, this is a ResultSource object, and it's what you're describing when you're writing e.g.

package MyApp::Schema::Result::Artist; use base qw/DBIx::Class::Core/; # this ResultSource is going to be based on a table, not a view __PACKAGE__->table('artist'); # the table has these columns __PACKAGE__->add_columns(qw/ artistid name /); # and this is the pkey __PACKAGE__->set_primary_key('artistid');

and then 2. get the pkey info from the ResultSource. So we get:

my $result_source = $schema->resultset('Artist')->result_source; my @list_of_columns_in_pkey = $result_source->primary_columns;

Edit: I just realized, I assumed you were starting from a ResultSet object, but if you already know its name beforehand:

my $result_source = $schema->source('Artist'); my @list_of_columns_in_pkey = $result_source->primary_columns;

Replies are listed 'Best First'.
Re^2: retrieving primary key from a DBIx::Class package
by Anonymous Monk on Apr 25, 2013 at 08:16 UTC
    Great! Works perfectly - thanks pokki !

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030475]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2018-06-19 15:07 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.