one to many relationship

197 views
Skip to first unread message

Bob Jansen

unread,
Sep 14, 2020, 5:43:07 AM9/14/20
to TiddlyWiki
could someone help me and advise on how to implement a one-to-many relationship in TW without the use of tags.

assume person buys many artworks. Each person and each artwork has a unique id since you cannot guarantee the uniqueness of titles.

I have been pondering for some days how to do this using either data structures, ie. intermediate tiddlers, or $list structures. The problem for me is that I do not yet fully understand $list structures, especially how to include a variable into the filter. I can get things to work with hard coded ids but not using a variable in the filter. And anyway, my method may not be optimum. 

All advice appreciated.

bobj

Jed Carty

unread,
Sep 14, 2020, 7:15:55 AM9/14/20
to TiddlyWiki
Do these relations need to be bi-directional? That makes things difficult enough that I made a plugin for it https://ooktech-tw.gitlab.io/plugins/relations/

if it only needs to go person -> artwork the easiest way is to use a list field in the persons tiddler that lists each artwork associated with them.

So in the tiddler for Person A you create a field called list
In the field you put in the title for each artwork to associate with the person, it would look something like this:

[[La Joconde]] Sphinx [[Elvis on Black Velvet]]

then to list the artwork associated with a person in the tiddler for that person you could use

<$list filter='[list[]]'>


</$list>


or to list the artwork associated with Person A in any tiddler you would use

<$list filter='[list[Person A]]'>


</$list>

there are other methods, using a data tiddler could also be a good choice but that may require more work to set up.

Bob Jansen

unread,
Sep 14, 2020, 7:32:07 AM9/14/20
to tiddl...@googlegroups.com
Jed

Thanks for your email 

I can’t use titles as they can not be guaranteed to be unique. That’s why every tiddler has a unique id.

I was thinking about a filed in the name riddler with the ids of the artworks but then how to display the titles?

Bobj

Dr. Bob Jansen
122 Cameron St, Rockdale NSW 2216, Australia
Skype: bobjtls

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/6I60ywWH5Fo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/94bf5445-6dfe-447b-864c-ac220aab8437o%40googlegroups.com.

Felicia Crow

unread,
Sep 14, 2020, 8:39:22 AM9/14/20
to TiddlyWiki
Hi,
so to extend Jed's solution I assume three things: Each tiddler for a person has a buyer-id field, each tiddler for an artwork has an artwork-id field and each person tiddler has an bought-artwork field that contains a space separated list of artwork-ids. If the artwork ids don't contain spaces themselves it is enough to just write the id otherwise you have to wrap the id in double square brackets like a link. Basically looking like what Jed had in his answer for the artwork names, but with your ids instead.

To show what artworks a person has bought you would use this triple list - probably preferably in a macro with the buyer-id being a macro parameter - to set the buyer-id, get the list of bought artwork and list out the artwork titles:
<$list filter="[!has[draft.of]field:buyer-id[specific_id_here]]">
<$list filter="[list[!!bought-artwork]sort[title]]" variable="artwork-id">
<$list filter="[
!has[draft.of]field:artwork-id<artwork-id>]">
<
<currentTiddler>>
</$list>
</$list>
</$list>

The outer most list just sets the currentTiddler to that of the person having this specific id as the list operator only works with either fixed references or the currentTiddler.
The next list takes the content of the bought-artwork field and turns it into an actual list of (pseudo) tiddlers. While the field passed to sort is title due to how things work, it actually essentially sorts by id. Setting the result to a variable in this step isn't essential, but may helps to make the readabilty of the next filter better.
The inner most list finally takes each id one after the other and looks for a tiddler that has a field artwork-id with the same value as the artwork-id it currently processes. If it finds such a tiddler it displays it.

In the other direction you would have this far smaller one list - once again could be put in a macro, just this time with the art-id being a parameter:
<$list filter="[!has[draft.of]has[buyer-id]contains:bought-artwork[specific_id_here]]">
<
<currentTiddler>>
</$list>

The filter here gets every tiddler that has a field buyer-id and then looks up for every one of them if the bought-artwork field contains the artwork-id.

Hope this helps!

Kind Regards,
Felicia
To unsubscribe from this group and all its topics, send an email to tiddl...@googlegroups.com.

Dr Bob Jansen

unread,
Sep 14, 2020, 10:06:07 AM9/14/20
to tiddl...@googlegroups.com
Felicia 

Thank you for your detailed reply. I will study it in the morning and make sure I follow what you are saying.

BobJ

---------------
Dr Bob Jansen
The Cultural Conversations project 
Turtle Lane Studios Pty Ltd trading as the Australian Centre for Oral History
Ph (Korea): +82 10-4494-0328 
Ph (Australia) +61 414 297 448 
Resume: http://au.linkedin.com/in/bobjan 
Skype: bobjtls 
KakaoTalk: bobjtls 
http://www.cultconv.com 

 In line with the Australian anti-spam legislation, if you wish to receive no further email from me, please send me an email with the subject "No Spam"
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2da4b35d-c3ed-478d-8149-1fa7960d7bf6o%40googlegroups.com.

Jed Carty

unread,
Sep 14, 2020, 10:26:04 AM9/14/20
to TiddlyWiki
The title field of the tiddler must be unique, so while the buyers may have a name field that does not need to be unique, it can not be the tiddler title. So use the tiddler titles as the unique field because they must be unique anyway.

TW Tones

unread,
Sep 14, 2020, 10:31:58 AM9/14/20
to TiddlyWiki
Bob,

If the tiddlers title is unique it could be as simple as  artworkname, artworkname 1 ...

However if you set the caption, captions need not be unique. They show in lists.

In your source example I could only see a one to many relationship.

Truth is tags are good at this, but I too try not to use them so as to not pollute the tag space and leave them for as needed relationships.

Mario published a gen tags, or alt tags plugin that allows additional tags like fields that are helpful in cases like this. But you can effectivly craft you own, the listops functions help with this.

Regards
Tones



On Tuesday, 15 September 2020 00:06:07 UTC+10, Dr Bob Jansen wrote:
Felicia 

Thank you for your detailed reply. I will study it in the morning and make sure I follow what you are saying.

BobJ

---------------
Dr Bob Jansen
The Cultural Conversations project 
Turtle Lane Studios Pty Ltd trading as the Australian Centre for Oral History
122 Cameron St, Rockdale NSW 2216, Australia 
Ph (Korea): +82 10-4494-0328 
Ph (Australia) +61 414 297 448 
Resume: http://au.linkedin.com/in/bobjan 
Skype: bobjtls 
KakaoTalk: bobjtls 
http://www.cultconv.com 

 In line with the Australian anti-spam legislation, if you wish to receive no further email from me, please send me an email with the subject "No Spam"

PMario

unread,
Sep 14, 2020, 6:29:42 PM9/14/20
to TiddlyWiki
On Monday, September 14, 2020 at 4:31:58 PM UTC+2, TW Tones wrote:

Mario published a gen tags, or alt tags plugin that allows additional tags like fields that are helpful in cases like this. But you can effectivly craft you own, the listops functions help with this.

That wasn't me. I think it's this: https://ooktech.com/jed/ExampleWikis/GenericTagFields/ what you meant.

-m

Dr Bob Jansen

unread,
Sep 14, 2020, 6:33:07 PM9/14/20
to tiddl...@googlegroups.com
Jed, 

Apologies, I mistook your title for the artwork title. I generate a unique ID and the use that as the tiddler title.

BobJ

---------------
Dr Bob Jansen
The Cultural Conversations project 
Turtle Lane Studios Pty Ltd trading as the Australian Centre for Oral History
122 Cameron St, Rockdale NSW 2216, Australia 
Ph (Korea): +82 10-4494-0328 
Ph (Australia) +61 414 297 448 
Resume: http://au.linkedin.com/in/bobjan 
Skype: bobjtls 
KakaoTalk: bobjtls 
http://www.cultconv.com 

 In line with the Australian anti-spam legislation, if you wish to receive no further email from me, please send me an email with the subject "No Spam"

On 15 Sep 2020, at 00:26, Jed Carty <inmy...@gmail.com> wrote:

The title field of the tiddler must be unique, so while the buyers may have a name field that does not need to be unique, it can not be the tiddler title. So use the tiddler titles as the unique field because they must be unique anyway.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/6I60ywWH5Fo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/685175bd-6cf5-4f65-b200-0d7cc68cce8eo%40googlegroups.com.

Dr Bob Jansen

unread,
Sep 14, 2020, 6:38:56 PM9/14/20
to tiddl...@googlegroups.com
Thanks for the link Marco, I'll check it out.

Can I just add a note of appreciation to this group, it is the most helpful group I have been a member of. I accept my questions must seem basic but as a newbie I am struggling through the TW concepts and usage. All the advice I have gotten over the past few days is incredibly helpful and not one troll.

Thanks again everyone.

BobJ

---------------
Dr Bob Jansen
The Cultural Conversations project 
Turtle Lane Studios Pty Ltd trading as the Australian Centre for Oral History
122 Cameron St, Rockdale NSW 2216, Australia 
Ph (Korea): +82 10-4494-0328 
Ph (Australia) +61 414 297 448 
Resume: http://au.linkedin.com/in/bobjan 
Skype: bobjtls 
KakaoTalk: bobjtls 
http://www.cultconv.com 

 In line with the Australian anti-spam legislation, if you wish to receive no further email from me, please send me an email with the subject "No Spam"
--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/6I60ywWH5Fo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/522a883a-48d9-4874-81f8-a920f5f730f7o%40googlegroups.com.

Dr Bob Jansen

unread,
Sep 14, 2020, 6:40:46 PM9/14/20
to tiddl...@googlegroups.com
Mario, 

Sorry about misspelling your name in my last message. I hate predictive spelling of the iPad. I usually check  but for some reason didn't that time.

BobJ

---------------
Dr Bob Jansen
The Cultural Conversations project 
Turtle Lane Studios Pty Ltd trading as the Australian Centre for Oral History
122 Cameron St, Rockdale NSW 2216, Australia 
Ph (Korea): +82 10-4494-0328 
Ph (Australia) +61 414 297 448 
Resume: http://au.linkedin.com/in/bobjan 
Skype: bobjtls 
KakaoTalk: bobjtls 
http://www.cultconv.com 

 In line with the Australian anti-spam legislation, if you wish to receive no further email from me, please send me an email with the subject "No Spam"
On 15 Sep 2020, at 08:29, PMario <pmar...@gmail.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/6I60ywWH5Fo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/522a883a-48d9-4874-81f8-a920f5f730f7o%40googlegroups.com.

TW Tones

unread,
Sep 14, 2020, 6:43:23 PM9/14/20
to TiddlyWiki
Bob,

Yes, tiddlywiki is in my view the "healthiest" online community group I have ever come across. 

Result: we all contribute more.

Tones
To unsubscribe from this group and all its topics, send an email to tiddl...@googlegroups.com.

Bob Jansen

unread,
Sep 14, 2020, 8:40:54 PM9/14/20
to TiddlyWiki
Colleagues,

after studying Felicia's contribution, it became immediately obvious that my initial tiddler structure was the problem in that my trial wiki added the artwork title as the tiddler title, which as I replied to Jed can't be correct since we can not guarantee the uniqueness of the artwork title. So, I changed the tiddler title to be the unique id, ie. BJ2, and this required changes to the artwork template for displaying details of an artwork since the user really only wants to see the artwork title and not the tiddler title. so underneath the artwork image, we now display the line of 

artwork_title, artwork_medium, artwork_size, artwork_yearofcreation

as is expected in a 'normal' caption.

Now this immediately made the following code work correctly.

<$list filter="[tag[Artworks]!<currentTiddler>search:purchased_by{!!title}sort[title]]">&bull; <$link to={{!!artwork_id}}><$view field="artwork_title"/></$link><br/></$list>

The important bit is the $view statement as that 'transcludes' the artwork_id with the artwork_title on display but links using the artwork_id and so correctly displays the correct artwork when clicked.

I guess a concern may be the search statement when the number of tiddlers gets very large but we'll cross that bridge when we come to it.

I am looking at the Generic Tag plugin and seeing if this provides a more useful mechanism.

Thanks to all for your input.

bobj
Reply all
Reply to author
Forward
0 new messages