Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: DBIx::Class and "complex" joins (was Re^4: DB: what kind of relationship?)

by 1nickt (Canon)
on May 04, 2020 at 01:50 UTC ( [id://11116415]=note: print w/replies, xml ) Need Help??


in reply to Re: DBIx::Class and "complex" joins (was Re^4: DB: what kind of relationship?)
in thread DB: what kind of relationship?

Thanks, Toby. Glad it was of interest.

With regard to the language issue; of course you are right that I over-simplified. I was trying to come up with a schema that could show some relatively complex joins: I thought about the family, the CD collection and the farm, but they've all been done ;-)

Language is a thorny problem. As you say, some artists might speak a primary language that can not be derived from their country, so Language should probably be a property of the Artist. And some artworks might indeed be "in" a language that is not the artist's primary language ... so the Language should also be an attribute of the Artwork ... but does a Painting have a Language? Probably it needs to be nullable, or maybe an attribute of only certain types of artwork in their respective tables.

With regard to the primary key in the Painting, Play and Poem tables, and having an extra column named <entity_type>_id, as I mentioned I prefer to have separate names because it can make column aliasing simpler, and also because it allows for future expansion.

What if I realize that most poets publish collections of poetry as an artwork? I will have to add a name column to the Poem table and backfill it. But other than that, all I have to do is drop one unique key:

unique key poem_artwork_uk (artwork_id)
... add a different multi-column unique key:
unique key poem_name_artwork_uk (name, artwork_id)
... rerun dbicdump, and my classes will be rebuilt with a one-to-many relationship between Artwork and Poems (with all custom code preserved).

Then I could get the number of Poems in the collection, or the other Poems, with code like:

my $poem = $db->resultset('Poem')->search( { 'me.name' => 'How Great It Is To Frobnicate', 'artist.name' => 'Toby Inks', }, { join => { artwork => 'artist' }, }, )->single; my $num = $poem->artwork->poems->count; my @other_names = map { $_->name } $poem->artwork->poems->search({ poem_id => { '!=' => $poem->poem_id }, })->all;

Won't be tweaking this demo any more for now though :-)

Thanks,
--nick


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^3: DBIx::Class and "complex" joins (was Re^4: DB: what kind of relationship?)
by tobyink (Canon) on May 04, 2020 at 07:22 UTC

    I'd say paintings can have a language; certain paintings have linguistic content. One that springs to mind is Campbell's Soup Cans by Andy Warhol. If ISO 639-2 codes are used to identify languages, there is a code zxx meaning no linguistic content that could be used for paintings with no text, music with no lyrics, etc. There's also mul for multiple languages. This is one of the cool features ISO 639-2 alpha-3 has over the more commonly used ISO 639-2 alpha-2 codes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-18 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found