Wt::Dbo join tables do not add foreign key constraints
Added by David Betz about 11 years ago
Using Wt::Dbo, I have classes Class and Student and a many-to-many relation between them. Class and Student use the default int id primary key. The join table which expresses the many-to-many relation is created by the following SQL:
create table "classes_x_students" (
"classes_id" bigint not null,
"students_id" bigint not null,
primary key ("classes_id", "students_id")
)
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "classes_x_students_pkey" for table "classes_x_students"
create index "classes_x_students_classes" on "classes_x_students" ("classes_id")
create index "classes_x_students_students" on "classes_x_students" ("students_id")
Shouldn't there be foreign key constraints on classes_id and students_id?
Replies (2)
RE: Wt::Dbo join tables do not add foreign key constraints - Added by Thomas Saquet about 11 years ago
Hello David,
As far as I know as another Wt::Dbo (heavy) user, yes there should be.
My own database has many join tables and I have the foreign keys.
How do you set the relationship between your classes in your code ?
Regards,
Thomas
RE: Wt::Dbo join tables do not add foreign key constraints - Added by Koen Deforche about 11 years ago
Hey David,
With more recent versions of Wt, Wt::Dbo will create the foreign key constraints after it created all the tables (since that's the only way it can do in general when there are many (circular) constraints.
Regards,
koen