in reply to Re^2: DB: what kind of relationship?
in thread DB: what kind of relationship?

Hi again Bliako,

"... Unless a JOIN can take additional conditions (like a WHERE comment_type='play' ..."

Heh. No reason to use DBIx::Class if not to make things easy ;-). Also please familiarize yourself with SQL::Abstract, which builds the SQL used by DBIx. That's where you'll learn how to build complex where clauses. The DBIx manuals have the info on join and prefetch and the relationships that DBIx creates for you. Note in the code below that the "join" is actually a DBIx relationship and thus the identifier "event" is the name of the relationship, not of the table (although it may be the same value, as here).

Using the schema I created above:

use strict; use warnings; use feature 'say'; use Bliako::Schema; my $db = Bliako::Schema->connect( 'DBI:mysql:database=Bliako', undef, undef, { RaiseError => 1 }, ); my @comments = $db->resultset('Comment')->search({ 'event.type' => 'concert', 'event.name' => 'Rolling Stones', }, { join => 'event', }); say sprintf( '%s said about the %s concert: "%s"', $_->user->name, $_->event->name, $_->text, ) for @comments;

Output:

$ perl -I. bliako-2.pl Bliako said about the Rolling Stones concert: "Greatest rock and roll +band in the world!" 1nickt said about the Rolling Stones concert: "There is cool, then the +re is Charlie Watts."

Hope this helps!


The way forward always starts with a minimal test.