SeaQL / SeaQL/sea-orm

`sea_orm_cli` doesn't generate the correct relation for a foreign key in a different schema

Open
#1,778 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

If a table has a foreign key relationship with a table in a different schema, sea doesn't generate the correct code. It seems to assume that all referenced tables will be in the one schema.

Probably relatively low priority, since you get an immediate compile error with an obvious fix and it's a relatively uncommon case to begin with.

Steps to Reproduce

  1. Create two schemata and a table for each, e.g. schema1.src and schema2.dest
  2. Add a foreign key constraint from one to the other, e.g. schema2.dest.src_id references schema1.src.id
  3. Generate the models with sea.
Expected Behavior

The relation will be generated with the correct model/entity references.

Actual Behavior

The relation is generated incorrectly, referencing a nonexistent table in the current schema.

Reproduces How Often

Always reproducible.

Workarounds

Editing the generated code with the actual path to the referenced module.

Reproducible Example

https://github.com/SeaQL/sea-orm/pull/1779

Versions

sea-orm-cli v0.11.0:
    sea
    sea-orm-cli
├── sea-orm v0.11.3
│   ├── sea-orm-macros v0.11.3 (proc-macro)
│   ├── sea-query v0.28.5
│   │   ├── sea-query-derive v0.3.0 (proc-macro)
│   ├── sea-query-binder v0.3.1
│   │   ├── sea-query v0.28.5 (*)
│   ├── sea-strum v0.23.0
│   │   └── sea-strum_macros v0.23.0 (proc-macro)

Ubuntu 22.04 on Windows 11 (WSL)

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 in the sea_orm_cli model-generation path and use the linked reproducible example to recreate tables in schema1 and schema2 with a cross-schema foreign key. Confirm that generated relation code references the model/entity in the referenced schema rather than a nonexistent table in the current schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.