-
Following this issue's example with songs and albums, I was wondering if it's possible to have an album automatically removed after I delete its last song. With the suggested setup, when I delete a song I can see the entry from |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello @phi161,
Indeed, deleting albums that have no song has to be done by the application. Assuming you have defined an // Delete empty albums that do not contain any song.
try Album.having(Album.albumSongs.isEmpty).deleteAll(db) See Association Aggregates for more information about
When rows are deleted from When rows are deleted from For more information about foreign keys and cascades, please see SQLite documentation. |
Beta Was this translation helpful? Give feedback.
-
Just as an alternative idea - I decided to leave it with the database if a record can be deleted
I think this is better to manage at db level. Imagine that later you introduce another table needing referencial integrity to the table Hope this makes sense |
Beta Was this translation helpful? Give feedback.
Hello @phi161,
Indeed, deleting albums that have no song has to be done by the application.
Assuming you have defined an
Album.albumSongs
hasMany
association, you can run the following line:See Association Aggregates for more information about
isEmpty
.When rows are deleted from