[v4] - How to delete with relationship #1857
-
Soo I have a class Delivery extends Model {
selected_driver() {
return this.hasMany('App/Models/SelectedDriver')
}
} class SelectedDriver extends Model {
user() {
return this.belongsTo('App/Models/User')
}
delivery_orders() {
return this.hasMany('App/Models/DeliveryOrder')
}
stocks() {
return this.hasMany('App/Models/Stock')
}
estimated_revenue() {
return this.hasOne('App/Models/EstimatedRevenue')
}
invoices() {
return this.hasMany('App/Models/Invoice')
}
} so what I want to ask is what is the best and easiest way to delete all of them when I delete A Delivery?? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is something that will be well done within the database using the |
Beta Was this translation helpful? Give feedback.
This is something that will be well done within the database using the
on delete cascade
option. If you are unaware of how this option works in SQL, then I recommend first reading a bit about and then you can use AdonisJS migrations to set theon delete cascade
when creating database tables