agronholm / agronholm/sqlacodegen

SQLModel does not generate many-to-many classes correctly

Đang mở
#405 8 bình luận 3 reaction 1 người được giao Được @sheinbergon nhận Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
2.4k
Fork
284
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Mô tả

### Things to check first

- [x] I have searched the existing issues and didn't find my bug already reported there

- [x] I have checked that my bug is still present in the latest release

### Sqlacodegen version

3.0.0

### SQLAlchemy version

2.0.38

### RDBMS vendor

PostgreSQL

### What happened?

Ran the command
```
sqlacodegen postgresql://postgres:postgres@localhost:5432/sentimental --generator sqlmodels --outfile data_pipelines/lib/models/pg_ext_sqlm.py
```
All tables generated correctly but the many-to-many class was not correct. The base metaclass was missing after the first parmeter **property_lead_link**.
```
t_property_lead_link = Table(
'property_lead_link', ,
Column('property_lead_id', Integer, primary_key=True, nullable=False),
Column('lead_link_id', Integer, primary_key=True, nullable=False),
ForeignKeyConstraint(['lead_link_id'], ['property_link.id'], name='fk_property_lead_link_link'),
ForeignKeyConstraint(['property_lead_id'], ['property_lead.id'], name='fk_property_lead_link_lead'),
PrimaryKeyConstraint('property_lead_id', 'lead_link_id', name='pk_property_lead_link')
)
```

### Database schema for reproducing the bug

```
CREATE TABLE public.property_lead (
id serial NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
);

ALTER TABLE public.property_lead ADD CONSTRAINT pk_property_leads PRIMARY KEY (id);

CREATE TABLE public.property_link (
id serial NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
);

ALTER TABLE public.property_link ADD CONSTRAINT pk_lead_links PRIMARY KEY (id);

CREATE TABLE public.property_lead_link (
property_lead_id integer NOT NULL,
lead_link_id integer NOT NULL
);

ALTER TABLE public.property_lead_link ADD CONSTRAINT pk_property_lead_link PRIMARY KEY (property_lead_id, lead_link_id);
ALTER TABLE public.property_lead_link ADD CONSTRAINT fk_property_lead_link_lead FOREIGN KEY (property_lead_id) REFERENCES public.property_lead(id);
ALTER TABLE public.property_lead_link ADD CONSTRAINT fk_property_lead_link_link FOREIGN KEY (lead_link_id) REFERENCES public.property_link(id);
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.