Yes…
The other two options could replace the status[0] != "done"
part, but are more verbose and thorough. They counter for the following variants:
status:
- todo
- done
...
status: done
If you imagine doing this query against multiple files, either variant could happen in some of the files, and the first naive options would fail for both of these variants. If however, you used some of the alternate versions, you’d counter for some of the possible scenarios. With having the status: done
case is the most pressing one, I think. It’s too easy to have the status
in one of the files suddenly become a single value.
A more complete test note
In the note below, which you could copy to your vault and fiddle around with, you could see varying cases on checking for “done” against either a list or a single value.
I’m using list( this.singleton, this.status)
to combine the two variant into the same, which would be similar to grouping on the same name, or looking at it from a multi file view point. this.
is needed to just pick the values from this current file in an inline query.
In the last query I do some magic to keep the lists as list, when combining list(flat(list(...)))
, just to keep the combined values as a values when intermediate storing them using FLATTEN
. Focus rather on the table columns, and know the values of values
and tests
are as in the previous query.
---
Tags: f74678
status:
- done
singleton: done
---
questionUrl:: http://forum.obsidian.md/t//74678
## Naive approach
first list item: `= this.status[0] = "done" ` – OK
as a singleton: `= this.singleton[0] = "done" ` – It _only_ compares against the first letter: `d`, and that's not `done`
correct for a single value: `= this.singleton = "done" ` – Now it compares against the entire string
## List combinations
combined list
```dataview
LIST WITHOUT ID list(this.status, this.singleton)
WHERE file = this.file
```
flattened combined list:
```dataview
LIST WITHOUT ID flat(list(this.status, this.singleton), 4)
WHERE file = this.file
```
The order of the list shouldn't change the outcome:
- v1: `= list(this.status, this.singleton)[0] = "done" ` – This is false, since the first element is a list
- v2: `= list(this.singleton, this.status)[0]= "done" ` – This is true, since we now got the singleton first
- Bad v1: `= list(this.status, this.singleton)[0][0] = "done" ` – This is true _only when the first element is a list_
- Bad v2: `= list(this.singleton, this.singleton)[0][0] = "done" ` – This becomes false, since we know against the first character of the singleton
Back to the good using the flattened list, we can check the first item reliably:
- v1: `= flat(list(this.status, this.singleton))[0] = "done" `
- v2: `= flat(list(this.singleton, this.status))[0] = "done" `
No matter which variant is first, we check it.. But we do ignore the second variant all together. (Try changing either, and see the changes )
## Checking all values
mapped list check:
```dataview
TABLE WITHOUT ID
flat(list(this.status, this.singleton)) as values,
map( flat(list(this.status, this.singleton)), (m) =>
m = "done" ) as tests
WHERE file = this.file
```
The final test shows the various alternatives after mapping:
```dataview
TABLE WITHOUT ID
values, tests,
any(tests),
all(tests),
none(tests)
WHERE file = this.file
FLATTEN list(flat(list(this.status, this.singleton))) as values
FLATTEN list( map(values, (m) => m = "done")) as tests
```
Now go back, and change either value to something else, and see the changes. Or even add more values to the `status`.