question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow for querying descendants - children recursively

See original GitHub issue

There is a need for this expressed https://www.getlektor.com/docs/api/db/record/children/ and on gitter.

To be clear, instead of returning only the direct, 1st generation children of a record, descendants would be recursive for the entire depth of the record and return all children of all depths.

We already have this.children recursive, but I think descendants still has a use, as it allows you to chain methods together more easily.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
xlotlucommented, Jul 20, 2020

I’d like to see glob patterns working in queries, and this would solve this here issue.

site.query('/blog-categories/*')

would be equivalent to the current behaviour.

But

site.query('/blog-categories/**')

would fetch everything recursively.

2reactions
torian257xcommented, Sep 19, 2017

true that would solve this exact issue and something like that is what I currently plan on doing.

now what about say, blog categories with sub categories?

e.g.

[fields.categories]
label = Categories
type = checkboxes
source = site.query('/blog-categories')
width = 1/2

I want not only ‘blog-categories’ but as well it’s sub categories.

something is missing, yes, if there is just one level of blog categories it works. But bad luck to you if you want to do something slightly different.

what about you want a resource in a different place than /resources as well? Say I have some videos as well in /training I already tried you cannot define the slug to be ../training/something that was btw one of the first things I tried with lektor.

the question: “get me all video records” can only be solved in the view via recursive function calls. I don’t think thats cool.

I say I want to query all records never matter where they are. And I want to have them available on model definition level. If it’s only available on view level, it limits in what I can do with it. And I want to run actually nice queries over all records. That is not something insane to ask for imho. By all means, if there is a way to achieve it, please tell me.

as soon as the structure gets a little bit more complex, the records are a bit spread out, the air gets really thin for lektor. And that wasn’t clear to me to begin with. And I don’t think it’s cool. It should be simple and fun to work with lektor.

On 19 September 2017 at 12:39, Andreas Runfalk notifications@github.com wrote:

If you want to sole the particular case /resources/something/slug I think you can solve that with children and one sub-folder:

  • You have the resources model
  • You have a resource model with some kind of way to distinguish between the different types
  • You set the URL slug to something like {{ this.type }}/{{ this._id }}, where type can be pdfs, white-papers, videos, etc. This will give you the URLs you want while still keeping a sane data model

I have not tried this, but in theory it seems very doable. You can read more about it on https://www.getlektor.com/docs/content/urls/

If that can be a solution to your particular issue I think adding descendants adds more complexity than it’s worth.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lektor/lektor/issues/445#issuecomment-330500226, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-d-sT_V2j1Zrq8Jq03GovuYU2iD2u1ks5sj5n-gaJpZM4PU3TC .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting all descendants of a parent - DBA Stack Exchange
According to the docs, Teiid does support recursive queries, you just need to omit the keyword RECURSIVE. (And while we are at it,...
Read more >
How to Get Descendants of a Parent in SQL | LearnSQL.com
Recursive Query : Retrieving the Descendants. First, let me show you what the query looks like. Then I'll break it down for you, ......
Read more >
Recursive query for parent child hierarchy. Get descendants ...
The below query will give you all the Parent - Child relationships that are descendants of 3. CREATE TABLE dbo.ParentChildRel ( Parent INT ......
Read more >
3.1.2 Example 2: Descendant - CS @ Union
Prolog has found a proof for the goal descend(caroline,laura) (the second recursive call). But this means that child(charlotte,laura) (the first recursive call) ...
Read more >
Hierarchical (Recursive) Queries in Valentina SQL
Let `s assume that we have a table with a self-recursive link: some record(s) as the parent record(s), and child-records having pointers to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found