-
-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect entity generation for relation with composite keys #1690
Comments
Hey @affanshahid, thanks for the report! I just checked and indeed it's happening. This PR should fix the issue. Feel free to check |
Now, it seems to be generating duplicate entries for the columns. Here is the table structure for the original table: CREATE TABLE "public"."project" (
"id" text NOT NULL,
"team_id" text NOT NULL,
"weekends" _text NOT NULL,
PRIMARY KEY ("id","team_id")
); The structure for the table with the FKs: CREATE TABLE "public"."share" (
"id" uuid NOT NULL,
"team_id" text NOT NULL,
"project_id" text NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "share_team_id_project_id_fkey" FOREIGN KEY ("team_id","project_id") REFERENCES "public"."project"("team_id","id") ON DELETE CASCADE,
PRIMARY KEY ("id")
); The generated code: use sea_orm::entity::prelude::*;
use serde::Serialize;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, poem_openapi :: Object)]
#[sea_orm(table_name = "share")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(column_type = "Text")]
pub team_id: String,
#[sea_orm(column_type = "Text")]
pub project_id: String,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::project::Entity",
from = "(Column::TeamId, Column::TeamId, Column::ProjectId, Column::ProjectId)",
to = "(super::project::Column::Id, super::project::Column::TeamId, super::project::Column::Id, super::project::Column::TeamId)",
on_update = "NoAction",
on_delete = "Cascade"
)]
Project,
}
impl Related<super::project::Entity> for Entity {
fn to() -> RelationDef {
Relation::Project.def()
}
}
impl ActiveModelBehavior for ActiveModel {} |
👋 Really appreciate the SeaQL community's work on SeaORM, thanks for working on this! It seems the associated PR has been approved for some time now, any update on when we'd be able to see this landed? |
Thanks for the nudge. I'll cross check with @billy1624 We should be able to include it in the next minor release, which should come out at the end of this week. |
I tested the most recent version of sea-orm-cli and I have the same problems as @affanshahid. For my entity with foreign key (id, version) it generates the following: #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::other_entity::Entity",
from = "(Column::Id, Column::Id, Column::Version, Column::Version)",
to = "(super::other_entity::Column::Id, super::other_entity::Column::Version, super::other_entity::Column::Version, super::other_entity::Column::Id)",
on_update = "NoAction",
on_delete = "NoAction"
)]
OtherEntity,
} |
@lucasmerlin can you share your schema for investigation? |
@lucasmerlin Thanks for the report. Actually we observed that too, so would be able to investigate. |
Should this issue be reopened until this is fixed? I could also create a new one |
Right. I think we need to patch SeaSchema as well. |
With the MusicBrainz Postgres DB (https://github.com/metabrainz/musicbrainz-docker), the relations are not generated. |
Hi, do you have any updates on this? Can you please tell me if this will be fixed in the next release? |
* Fixes SeaQL#100 * Should also fix SeaQL/sea-orm#1690
Description
The generated entity is incorrect if the relation has a composite key.
Steps to Reproduce
First, create a table with a composite primary key.
Second, create another table with two foreign keys columns pointing to the original table.
Third, run the cli to generate entities.
Expected Behavior
The generated entities should have the correct values for the
from
andto
attributes in the generatedRelation
enum.Actual Behavior
The generated entity randomly points to one of the primary key columns
Reproduces How Often
Always, reproducible.
Workarounds
Manually updating the attributes to the correct value works fine.
Versions
The text was updated successfully, but these errors were encountered: