SeaQL / SeaQL/sea-orm

Support "Nest" for `DerivePartialModel` and `FromQueryResult`

Open
#1,715 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Motivation

When I implement the DerivePartialModel I find I can't implement SelectTwoMany::all_partial_model because of no primany key to consolidate result. I think it may can be solved.
If support “Nest”, then we can construct following PartialModel
(I suppose the PrimaryKeyTrait has an associate type PartialModel whitch contain all of its primany key)

#[derive(FromQueryResult, DerivePartialModel)]
struct TwoManyWithPk<E, M>
where
    E: Entity,
    M: PartialModelTrait + FromQueryResult
{
    #[sea_orm(flatten)]
     pk: <<E as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::PartialModel,
    #[sea_orm(flatten)]
    payload: M
}

That can make consolidate result possible

This is not only advance of Support "Nest" for DerivePartialModel and FromQueryResult. I believe it will useful in many condition.

Proposed Solutions

add derive macro argument flatten for derive macro PartialModelTrait and FromQueryResult , mark specified field became "Nest". this require the type of this field implement PartialModelTrait and FromQueryResult

Current Workarounds

Manual writing PartialModel with each field and cannot using preivous exits PartialModel

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the DerivePartialModel and FromQueryResult derive macros, then read how PartialModelTrait and PrimaryKeyTrait are defined and how SelectTwoMany::all_partial_model consolidates results. The issue is done when a field marked with the proposed flatten argument can represent a nested type implementing the required traits and supports the described primary-key use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.