I'm not sure if "subquery" is the appropriate term in my question. I'm new to DBIx. I'm using the WordPress::DBIC::Schema module.

I have the following module:

use Moose; use WordPress::DBIC::Schema; use namespace::autoclean; has 'schema' => (is => 'ro', isa => 'WordPress::DBIC::Schema', lazy => 1, builder => '_set_schema'); has 'rs' => (is => 'ro', isa => 'DBIx::Class::ResultSet', lazy => 1, builder => '_set_resultset'); has 'results' => (is => 'ro', isa => 'WordPress::DBIC::Schema::ResultSet::WpPost', lazy => 1, builder => '_set_results'); sub _set_schema { my $s = shift; my $db = $s->subdomain; my $user = $s->_db_user; my $pass = $s->_db_pass; my $schema = WordPress::DBIC::Schema->connect("dbi:mysql:database=$d +b", $user, $pass); return $schema; } sub _set_resultset { my $s = shift; return $s->schema->resultset('WpPost'); } sub _set_results { my $s = shift; return $s->rs->search({ post_type => 'nav_menu_item' }, { order_by => { -asc => 'id' } }); } sub dump_meta { my $s = shift; my %ids; while ( my $thing = $s->results->next ) { logd $thing->post_title; my $id = $thing->id; foreach my $meta ($thing->metas) { $ids{$id}{$meta->meta_key} = $meta->meta_value; } } $s->results->reset; logd \%ids; } sub get_title { my $s = shift; my $id = shift; my $results = $s->results->find($id); my $title = $results->post_title; if ($title) { return $title; $s->results->reset; } ############# Trying to figure out this part, does not work ######## +############ my $post_id = $results->metas->select('_menu_item_object_id'); print $post_id . "\n"; }

So the dump_meta function works fine. You can see there how the meta values associated with a post are printed out. I want to try to access a single meta_value for an associated meta_key in the get_title method. I could loop through all the values like I did in dump_meta and pull it out that way but I'm wondering if there is a better way. Thanks!

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to How to do a DBIx subquery? by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.