Hi List!
I'm building an application in base-x that's sort of like a local music wiki: bands, members, venues, promoters, and albums and songs are some of what I'm representing in XML.
And what I'm wondering is that, in a situation where there's one of something (a musician), and a bunch of something else they're associated with (song writting or performance credits), which node should get the reference?
The numerous node gets the reference back to the one:
<album name="We Might Rock You" by="The Quesadillas"> <track number="1" name="Hot Cross Buns" written-by="Joe Schmoe" /> <track number="2" name="Bicycle" written-by="Joe Schmoe" /> </album> [ etc ]
Or the one refers to the many:
<person name="Joe Schmoe"> <songs-written> <song name="Hot Cross Buns" /> <song name="Bicycle" /> </songs-written> </person>
Example 1, I could use something like:
track[@written-by="Joe Schmoe"]
Example 2:
person[@name="Joe Schmoe"]/songs-written/song
My other thought was putting the references in both, but I'll have to do this with many types of objects I'm representing and I don't want things to get out of control (then again, if I go to export an <album/> or <band/> and I'm using the second method, I'll have to do a join)
I have a feeling in a large set, the second way wins out. Even where I live, with only around 750,000 people in our entire state (Alaska), we have easily 100 - 200 acts, including bands, solo performers, traditional acts, etc, with thousands of individuals that compose them. But I want bands that are extinct, bands that are on hiatus, etc, and I hope my software is useful to others in larger cities as well.
So, maybe a pointless question because my db will be so tiny compared to some folks who post on here, but just curious :-)
Also, if this problem has a name I can research myself, that'd be great!
Be well, Jay Straw
Hi Jay,
You are asking for advice, so here is mine :
Working with BaseX, you shall get rid of any entity/relationship model (or stick to java JPA plumbing), and focus on the documents or the messages your application will exchange.
Each document might be identified - either by path and/or an unique attribute or element, for cross references (maybe with xml:base attribute ?).
At first glance, one could think of the following document types :
- Artist or Band (auto referencing Artists)
- Album (including Songs)
- Tour
As I write, I just realize that your question could be all about the distinction between aggregation and reference relations in the object world (just think of the Eiffel expanded keyword).
Good designing !
Best regards,
Fabrice ETANCHAUD SPI Informatique
De : basex-talk-bounces@mailman.uni-konstanz.de [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de Jay Straw Envoyé : mercredi 29 mars 2017 03:16 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Performance: associating one with many, or many with one?
Hi List!
I'm building an application in base-x that's sort of like a local music wiki: bands, members, venues, promoters, and albums and songs are some of what I'm representing in XML.
And what I'm wondering is that, in a situation where there's one of something (a musician), and a bunch of something else they're associated with (song writting or performance credits), which node should get the reference?
The numerous node gets the reference back to the one:
<album name="We Might Rock You" by="The Quesadillas"> <track number="1" name="Hot Cross Buns" written-by="Joe Schmoe" /> <track number="2" name="Bicycle" written-by="Joe Schmoe" /> </album> [ etc ]
Or the one refers to the many:
<person name="Joe Schmoe"> <songs-written> <song name="Hot Cross Buns" /> <song name="Bicycle" /> </songs-written> </person>
Example 1, I could use something like:
track[@written-by="Joe Schmoe"]
Example 2:
person[@name="Joe Schmoe"]/songs-written/song
My other thought was putting the references in both, but I'll have to do this with many types of objects I'm representing and I don't want things to get out of control (then again, if I go to export an <album/> or <band/> and I'm using the second method, I'll have to do a join)
I have a feeling in a large set, the second way wins out. Even where I live, with only around 750,000 people in our entire state (Alaska), we have easily 100 - 200 acts, including bands, solo performers, traditional acts, etc, with thousands of individuals that compose them. But I want bands that are extinct, bands that are on hiatus, etc, and I hope my software is useful to others in larger cities as well.
So, maybe a pointless question because my db will be so tiny compared to some folks who post on here, but just curious :-)
Also, if this problem has a name I can research myself, that'd be great!
Be well, Jay Straw
Dear Jay,
And what I'm wondering is that, in a situation where there's one of something (a musician), and a bunch of something else they're associated with (song writting or performance credits), which node should get the reference?
I would go with the first approach (listing the track names along with the album). If you plan to build a potentially larger database, I would advise to use ids instead of plain names. This will ensure that people with the same name won’t get mixed up, and updates will be much faster.
Your data could look as follows:
albums.xml: <albums> <album id='album0' by="artist0"> <name>We Might Rock You</name> <track name="Hot Cross Buns" written-by="artist1" /> <track name="Bicycle" written-by="artist1" /> </album> </albums>
artists.xml: <artists> <artist id='artist0'> <name>The Quesadillas</name> </artist> <artist id='artist1'> <name>Joe Schmoe</name> </artist> </album>
If all documents are stored in a database 'music', the following query will give you the names of all albums by a specific band:
let $artist := 'The Quesadillas' let $artist-id := db:open('music')/artists/artist[name = $artist]/@id let $albums := db:open('music')/albums/album[@by = $artist-id] return $albums/name/string()
• I have removed the track number from your original examples because it can be derived from the order of the track elements. • I have moved names to elements. This was just by preference: Your documents may be better readable if attributes are only used for ids and short values. • If you use ids, and if you have updates, you will need to take care that each id is only assigned once. If you use util:uuid() instead, you’ll be (as good as) safe.
All the best to Alaska, Christian
basex-talk@mailman.uni-konstanz.de