Skip to content

Typed Filtering Support for Non-Relational Model Properties #4285

Open

Description

@SandPod

Problem to Solve

Currently, Serverpod does not support typed filtering for model properties that are stored in fields and are not represented as relations. This makes it difficult to select rows based on sub-properties of embedded objects, leading to increased reliance on raw queries and decreased type safety.

Proposal

Introduce a typed filtering interface for model properties stored in non-relational fields. The interface should:

  • Allow typed, ergonomic filtering on serialized fields and their sub-properties
  • Integrate seamlessly with Serverpod's code generation and conventions
  • Enable developers to filter/query based on values inside embedded objects or lists using a type-safe builder API
  • Include comprehensive documentation and usage examples
  • Optionally support integration tests to validate filtering behavior across embedded objects/lists

Model Example (Serverpod YAML):

class: Settings
fields:
  notificationsEnabled: bool
  theme: String

class: User
table: users
fields:
  name: String
  settings: Settings

API Example:
Suppose you want to filter users whose embedded settings.notificationsEnabled value is true:

final filteredUsers = await User.db.find(
  session,
  where: (u) => u.settings.notificationsEnabled.equals(true),
);

This would translate to a type-safe query, finding all users whose settings.notificationsEnabled sub-property is true.

Use Case

A real-world use case is filtering a list of users based on roles and preferences stored in a JSON column; e.g., retrieve all users with role == "admin" or a specific setting enabled. With typed filtering, developers can construct queries without writing raw SQL or manual deserialization, making code safer and more maintainable.

Alternatives

Alternatives considered include writing custom SQL queries or using generic JSON operations. These methods lose type safety, increase boilerplate, and require manual maintenance as models evolve. Another alternative is mapping the embedded properties to their own tables, but this adds schema complexity when strict relational mapping isn’t necessary.

Additional context

This proposal builds on the discussion in #1591 and aims to extend filtering capabilities beyond only checking for nullness. A robust filtering API for embedded/serialized model data improves discoverability and code quality across larger codebases, especially where rich models aren’t easily normalized.

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added
    enhancement
    area: models
    on Nov 24, 2025
  2. moved this from Inbox 📫 to Backlog 🗂️ in Serverpod Frameworkson Nov 28, 2025
  3. iampopal commented on Apr 15, 2026

    @iampopal

    @SandPod this is a great place to start it..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: modelsenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions