Bases, Links, and Lists

Can someone explain to me, why this does not work:

I have a property as type list, e.g.

list_property:
 - "[[MATCH]]"
 - "[[title|MATCH]]"

In a formula

list_property.filter(value.contains("MATCH"))

matches the first but not the latter. BUT using

list_property.filter(value.toString().contains("MATCH"))

matches both. Why?

It feels like I have to add toString() to every query thats uses lists with contains() to receive the results I am looking for.

I hope that if someone can explain the reasons to me, I will understand the functions / syntax better in future. Many thanks in advance!

That’s a good question because it’s easy to expect the same result from both of those values.

So in Bases, a link is not some long string that happens to have square brackets. A link is its own kind of entity. It is a link type. So regardless of whether they have display text, both [[MATCH]] and [[title|MATCH]] are link type values. The first is a link to MATCH.md and the second a link to title.md.

Your second value requires toString because your aim is to look in the string[[title|MATCH]]” for the substring “MATCH”.

But without toString, you’re looking in the link [[title|MATCH]]. Since a link isn’t a string and doesn’t contain substrings, there’s no “MATCH” to be found. That is, until you toString it, which outputs a string that you can parse for substrings.

As for why the first value returns true without toString

Per the docs, anyString.contains() takes a string type in the parentheses. But anyList.contains() takes any type.

When you perform "[[MATCH]]".contains("MATCH"), Bases is able to resolve that as “list contains link” and returns true.


(edit:)

After posting, I thought to test a third value, [[MATCH|lorem]], which returns true both with and without toString. I also thought to create an error on "[[title|MATCH]]" so that the error message would tell me its type. It’s a list.

So I’m now pretty confident in the reasoning and deleted a bunch of weasel-wording that I used.

2 Likes

Dear dawni,

thank you very much, especially for taking the time to explain the circumstances to me. I really appreciate this.

I understand it a little better now from a technical standpoint. As a mere user, I am still confused by the mixed results.

Anyhow, I wonder if the approach I chose with toString() is the correct procedure, or if I have a list with wiki links and also want to check their “display names” (the part afer “|”), another approach might be better.

Kind regards

Marco

I think you’re using a very good approach.

It suits your goal of finding “MATCH” in either the display text or the note’s name.

Bases doesn’t have a function for returning a link’s display text separately from the note name. But if you ever do want to separate the two, then looking at the note name exclusive of the display text is as simple as

list_property.contains(link("MATCH"))

This also works:

list_property.filter(value == link("MATCH"))

Looking at the display text exclusive of the note name, however, is a fine time to use regex. Or take the long way around with a filter like:

list_property.filter(value.toString().split("|")[1].contains("MATCH"))
1 Like

Again, thank you very much! I’ve learned a lot :star_struck:.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.