Mjoin not delete data in the link table
Mjoin not delete data in the link table

.MJoin(new MJoin("Countries")
.Link("Trip.Trip_Id", "Trip_Countries.Trip_Id")
.Link("Countries.Country_Id", "Trip_Countries.Country_Id")
.Model<Model.Countries>()
.Order("Countries.Country_Id")
.Field(new Field("Country_Id")
.Options("Countries", "Country_Id", "Country_Name")
))
.MJoin(new MJoin("DayTrip")
.Link("Trip.Trip_Id", "Trip_DayTrip.Trip_Id")
.Link("DayTrip.DayTrip_Id", "Trip_DayTrip.DayTrip_Id")
.Model<Model.DayTrip>()
.Order("DayTrip.DayTrip_Id")
.Field(new Field("DayTrip_Id")
.Options("DayTrip", "DayTrip_Id", "TripName")
));
editor.Process(formData);
DtResponse data = editor.Data();
return Json(data, JsonRequestBehavior.AllowGet);
in the first mjoin the data deleted in the Trip_Countries table
but in the second mjoin in the table Trip_DayTrip the data cant be delete
because "The DELETE statement conflicted with the REFERENCE constraint "FK_Tours_Trip". The conflict occurred in database "Pegasus_Operation", table "dbo.Tours", column 'TripId'. The statement has been terminated.
"
This discussion has been closed.
Answers
Hi,
It sounds like you need to add a
ON DELETE CASCADE
to your references. Otherwise the database's referential integrity is preventing you from removing rows which are referenced from somewhere else.The other option, if you didn't want to cascade delete would be to add a validator to ensure that the row isn't externally referenced before it is deleted.
Allan
Also, can you show me the schema for your Trip_DayTrip link table? It should only contain a reference to the two tables it linked together. Any other data would be lost.
Allan