Things I have tried
I have searched both the forums and the help files on the dataview plugin. Intuitively I want to say that what I am doing is possible, but I haven’t figured it out yet.
Previous attempts include:
list
from #plantae and -"templates"
where companion.deters = any(this.conditions.vulnerable_to)
(returns no results)
and
list
from #plantae and -"templates"
where any(companion.deters) = any(this.conditions.vulnerable_to)
(results any file in which companion.deters is not empty - not actually sure why)
and
list
from #plantae and -"templates"
where contains(companion.deters,any(this.conditions.vulnerable_to))
(returns no results)
and
where filter([this.conditions.vulnerable_to], (x) => contains(companion.deters,x))
Returns results that do not even include the YAML keys I am querying.
What I’m trying to do
I am putting together a small compendium of plants and herbs. I would like to use dataview to show the interrelationships between these plants. I could solve this by writing the dataview query manually in every file, e.g.
list
from #plantae and -"templates"
where contains(companion.deters, "aphids") or contains(companion.deters, "some other pest")
but I would then have to update the query manually every time, for every plant. For a plant like broccoli, the query would also become incredibly long, as it has many pests it suffers from and many plants it works well with. I am wondering if there is a more scalable solution where I compare the contents of the vulnerable_to array in this file, to the contents of the deters array in other files, so that I can write the query once in my master template and have it run dynamically based on the YAML of the file in which it’s being executed.
Truncated YAML for the broccoli file below:
---
aliases: [Brassica oleracea]
kingdom: plantae
type: vegetable
lifecycle: biennial
conditions:
vulnerable_to: [slugs, snails, birds, clubroot, caterpillars, aphids]
companion:
traps:
deters:
attracts:
assists: [lettuce, swiss chard, radishes]
inhibits: [tomatoes, pole beans, strawberries]
---
(I have included aphids as a test)
Truncated YAML for the Thyme file which it should, in theory, retrieve:
---
companion:
deters: [cabbage worms, cabbage moths, cabbage loopers, beetles, aphids, blackflies]
---
Note that if I change the vulnerable_to field to only one value, e.g. “aphids” and then run the following query, it works perfectly:
---
conditions:
vulnerable_to: aphids
---
list
from #plantae and -"templates"
where contains(companion.deters,this.conditions.vulnerable_to)
However, when I then change the vulnerable_to field back to an array, the condition above returns all sorts of unrelated results. Is there a way to write the above function so that it loops through all the keys in the vulnerable_to array?
If anyone has tips or suggestions they would be very much appreciated!
Thank you