Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by tobyink (Canon)
on May 03, 2020 at 20:58 UTC ( [id://11116407]=note: print w/replies, xml ) Need Help??


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

A very comprehensive answer. I am suitably impressed. There are two things I'd do differently.

You noted that your cultural stuff was simplistic. It makes the error of associating languages with countries. An artwork being produced by an artist who lives in the UK in no way means that the artwork is in English. It may be artwork in a foreign language. It may be artwork produced a long time ago. (Latin was once the official language here.) It may be artwork in a British minority language such as Irish Gaelic, Welsh, Scots, Scottish Gaelic, Cornish, or Cumbric. (Side note: prior to Brexit, the UK used to get funding from the EU for supporting Irish Gaelic as a minority language. It is also spoken as a minority language in the Republic of Ireland, but they are ineligible for getting similar funding because although it's spoken by a minority of Irish people, it is one of Ireland's two official languages, and you can't get funding for supporting your own official language. Other side note: Scots and Scottish Gaelic are two entirely different languages. Scots is a cousin of Modern English. Modern English and Scots both evolved from different dialects of Old English. Scottish Gaelic is more closely related to Irish Gaelic, Welsh, Cornish, and Cumbric. Scots and Scottish Gaelic are about as related as French and Greek.)

The other thing I'd do differently is to drop these three columns entirely:

create table painting ( painting_id smallint unsigned not null primary key auto_increment, create table poem ( poem_id smallint unsigned not null primary key auto_increment, create table play ( play_id smallint unsigned not null primary key auto_increment,

All three of these tables already have a column which is not null and with each row having a unique numeric value.

  • Comment on Re: DBIx::Class and "complex" joins (was Re^4: DB: what kind of relationship?)
  • Download Code

Replies are listed 'Best First'.
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

    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.

      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://11116407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found