Album-to-song and tracklists relationships
Hi. First of all, thanks for SMW, a great software solution. I've just discovered it recently, and it looks really cool. I'm a long-time MediaWiki user and maintain a public music band wiki. I'm going to start a new project and now I would like to introduce SMW to avoid the existing wiki problems. I have a local playground where I do my SMW experiments, and I'm wondering if it's possible to make an album tracklist solution (one-to-many). Let's say, there is an album titled ALBUM and it contains the following template invocation:
{{Tracklist | TRACK1 | TRACK2 | TRACK3 | TRACK4 }}
The Tracklist template is as follows:
<includeonly> {{#fornumargs: I | V | {{#set: Type=tracklist |Collection={{FULLPAGENAME}} |Version={{{Version|}}} |Index={{#var: I}} |Song={{#var: V}} }} }} </includeonly>
It produces:
{{#set|Type=tracklist|Collection=ALBUM|Version=|Index=1|Song=SONG1}} {{#set|Type=tracklist|Collection=ALBUM|Version=|Index=1|Song=SONG2}} {{#set|Type=tracklist|Collection=ALBUM|Version=|Index=1|Song=SONG2}} {{#set|Type=tracklist|Collection=ALBUM|Version=|Index=1|Song=SONG4}}
And when, by my intention, I'm trying to query a tracklist for the album, I get a grouped result unfortunately (as far as I understand, this is how SMW works):
==Tracklist== {{#ask: [[Type::tracklist]] |?Collection |?Version |?Index |?Song }}
turns into a one-row table (format=ol
produces a single line list) because of grouping:
+---------+------------+---------+-------+--------+ | | Collection | Version | Index | Song | +---------+------------+---------+-------+--------+ | | | | 1 | SONG 1 | | | | +-------+--------+ | ALBUM | ALBUM | | 2 | SONG 2 | | | | +-------+--------+ | | | | 3 | SONG 3 | | | | +-------+--------+ | | | | 4 | SONG 4 | +---------+------------+---------+-------+--------+
After all, the whole ALBUM just got 4 properties, and this is why the result is grouped. I would like to "ungroup" it as if it's a SQL-like query without a GROUP BY clause. The only solution I see is spreading the tracklist information onto each of 4 song pages, like {{#set|Type=tracklist|Collection=ALBUM|Version=|Index=1|Song=SONG1}}
thus associating the tracklist album/index with a particular song, not the album itself where I'd expect to store the actual tracklist I used to do in my existing non-SMW wiki. This may look unusual, odd and violationg the SMW principles. Sorry for probably a vague explanation.
My question is as follows: what would you suggest to "ungroup" the result? Does my SQL-like idea violate the SMW principles? Any comments are appreciated. Thanks!
To build a one-to-many relationship for a subject (e.g. Album entity) it would be best to use the #subobject instead of #set.
{{#subobject: |Type=tracklist |Collection={{FULLPAGENAME}} |Version={{{Version|}}} |Index={{#var: I}} |Song={{#var: V}} }}
{{#ask: [[Collection::{{FULLPAGENAME}}]] |?Version |?Index |?Song |mainlabel=- }}
See also Examples/Queries/Subobject to display table rows
> music band wiki. I'm going to start a new project and now
You may want to look at [0] to get some ideas about a music related wiki that uses SMW.
One more question, please. Is it possible to refer the properties defined at the "sub/child"-pages? I would like to extend the above template/table output with the "Length" column so it could look like a real tracklist. The ?Song
property refers to song pages, and every song page has a song definition with the Length
property set. It's like the INNER JOIN
operation, but I feel like I'm abusing SMW capabilities (and it looks like I'm more of finding a search mechanism like XPath). Is it possible somehow?
In case you go with the #subobject then your data model will most likely be something like:
- An ALBUM is represented by a wikipage ->
- Subobjects are embedded in a page to represent each individual song ->
- Each song has attributes like:
- Song title
- Song index
- Song length
- Song author/composer/writer (optional in case it is a compilation where a song can have different writers from the Album)
- etc.
As demonstrated you attach attributes/properties to an individual song which a #subobject not a page (we are talking about an entity)
If you want to split an ALBUM/SONG by page/subpage then you can take a similar approach only that subobjects need to contain a reference to the album.
For example, looking for an album of song writer YYY where you want to see songs with title and length -> [[Has song writer::YYY]]|?Song title|?Song length.