${query[[
from p = index.tag "page"
where p.type=="contact"
select acction=query[[
from p2 = index.tag "page"
where table.includes(p2.contacts, p.name)
]]
]]
}
Action page has yaml
---
type: action
contacts: fred, peter
---
Contact page has yaml
---
type: contact
name: fred
---
My v1 query has each into each:
{{#each @p in {page where tipo and 'contacto' in tipo order by titulo}}}
{{#each @p2 in {page where tipo and 'accion' in tipo and @p.name=contactos ) }}}
[[{{@p2.name}}|{{@p.titulo}} -> {{@p2.titulo}}]] {{/each}} {{/each}}
Page name: 0004
---
type: contact
pname: fred
---
Page name: 0005
---
type: contact
pname: peter
---
I find list actions pages replacing pagename contact for contact’s field pname.
Expected result, a list
action page name, contact page pname
001, fred
002, peter
V1 silverbullet allows this (query first comment) but I haven’t been able to do it since version 2.
${
query[[
from query[[
from p = index.tag "page"
where p.type=="action" and p.contacts
select {
p.name,
query[[
from p2 = index.tag "page"
where p2.type=="contact" and p2.name==p.contacts
select p2.pname
]]
}
]]
]]
}
The select clause is not like a SQL clause in that it simply returns a Lua expression. What this means:
select {
p.name,
query[[
from p2 = index.tag "page"
where p2.type=="contact" and p2.name==p.contacts
select p2.pname
]]
}
is: return a table (array in this case) with two values: p.name and the entirety of the query result of query[[...]]
What you are probably looking for instead is something along the lines of
select {
name = p.name,
pname = (query[[...]])[1]
}
not really in a position to test this exactly, but this should directionally work. Your sub-query returns a collection of strings, and you pick the first element (which in Lua has index 1).
${query[[
from p=index.tag "page"
where p.type=="accion"
select
{p.name, query[[
from p2.index.tag "page"
where p2.name=="test"
select p2.name
]]}
]]
}
This is possible?
${query[[
from p=index.tag "page"
where p.type=="accion"
select
{p.name, query[[
from p2.index.tag "page"
where p2.name==p.related_name #attention to "p." not "p2." this is a yaml field of main query
select p2.name
]]}
]]
}
It seems to me that you are not exactly applying Zef Hemel’s suggestion: the 2nd query is in parentheses and brackets then, ultimately, you have to choose an index position ([1]).