Hi Bliako,

I build my schemas the other way, from the database which I have created via an SQL file. I find the DBIx::Class code too gnarly to write by hand!

I used the following schema:

use Bliako; drop table if exists comment; drop table if exists event; drop table if exists user; create table user ( user_id smallint unsigned not null primary key auto_increment, name varchar(32) not null ); create table event ( event_id smallint unsigned not null primary key auto_increment, type enum('play','concert') not null, name varchar(32) not null, unique key type_name_uk (type, name) ); create table comment ( comment_id smallint unsigned not null primary key auto_increment, user_id smallint unsigned not null, event_id smallint unsigned not null, text blob, key event_id_key (event_id), key user_id_key (user_id), unique key event_user_uk (event_id, user_id), constraint event_id foreign key(event_id) references event (event_ +id), constraint user_id foreign key(user_id) references user (user_id) ); insert into user values (null, 'Bliako'), (null, '1nickt'); select user_id into @bliako_id from user where name = 'Bliako'; select user_id into @1nickt_id from user where name = '1nickt'; insert into event values (null, 'play', 'Hamlet'); insert into event values (null, 'concert', 'Rolling Stones'); select event_id into @play_id from event where name ='Hamlet'; select event_id into @concert_id from event where name ='Rolling Stone +s'; insert into comment values (null, @bliako_id, @play_id, 'Somewhat depressing'), (null, @bliako_id, @concert_id, 'Greatest rock and roll band in the +world!'), (null, @1nickt_id, @concert_id, 'There is cool, then there is Charli +e Watts.');

Then I created the DBIx schema with:

$ dbicdump -o dump_directory=. Bliako::Schema 'dbi:mysql:database=Blia +ko'

My test script:

use strict; use warnings; use feature 'say'; use Bliako::Schema; my $db = Bliako::Schema->connect( 'DBI:mysql:database=Bliako', undef, undef, { RaiseError => 1 }, ); for my $username ('Bliako', '1nickt') { my $user = $db->resultset('User')->search({ name => $username })-> +first; for my $comment ( $user->comments->all ) { say sprintf( '%s said about the %s "%s": "%s"', $username, $comment->event->type, $comment->event->name, $comment->text ); } }

Output:

perl -I. bliako.pl Bliako said about the play "Hamlet": "Somewhat depressing" Bliako said about the concert "Rolling Stones": "Greatest rock and rol +l band in the world!" 1nickt said about the concert "Rolling Stones": "There is cool, then t +here is Charlie Watts."

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: DB: what kind of relationship? by 1nickt
in thread DB: what kind of relationship? by bliako

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.