Virtual page from database: drafts not showing in panel

I have just finished a project using a database. Everything is working fine. In the blueprints for collections I first used one section showing all records combined. As a last step I now want to turn these collections blueprints into the Kirby-style three sections Drafts, Unlisted, and Listed. But I fail to list the drafts.

Blueprint:

sections:
  collection1:
    headline: Drafts
    type:     pages
    status:   draft
    template: item
  collection2:
    headline: Unpublished
    type:     pages
    status:   unlisted
  collection3:
    headline: Published
    type:     pages
    status:   listed

This is the code in the Item class:

  public function isDraft(): bool {
    return $this->content()->data()['status'] === 'draft';
  }

  public function isListed(): bool {
    return $this->content()->data()['status'] === 'listed';
  }

  public function isUnlisted(): bool {
    return $this->content()->data()['status'] === 'unlisted';
  }

When I echo the value of $this->content()->data()[‘status’] in these three methods, this is what I get for isListed() and isUnlisted():

draft
draft
listed
listed
listed
unlisted
draft
listed
unlisted
draft

And for isDraft() the result is:

listed
listed
listed
listed

… which does not make sense, as it only queries the four ‘listed’ records instead of all ten.

It seems that when isDraft() is called, some filtering towards the ‘listed’ ones has already been applied, but I have not been able to find out where this is happening.

Those two are duplicated with different results (should be unrelated to the drafts, but still)

Thank you. I corrected it in the OP.

Are drafts() re-defined in your parent page model?

Thank you very much for that tipp. It works when I add this to the parent page:

  public function drafts() {
    return $this->children()->filter('status', 'draft');
  }

It might make sense to also redefine childrenAndDrafts(), just in case, you never know if you need it or not.

I think I’m going to separate the creation of children() and drafts(), despite that the data is coming from the same table in the database.