`sea_orm_cli` doesn't generate the correct relation for a foreign key in a different schema
Nobody has claimed this yet.
- 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
- Create two schemata and a table for each, e.g.
schema1.srcandschema2.dest - Add a foreign key constraint from one to the other, e.g.
schema2.dest.src_id references schema1.src.id - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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