From 4aed69fb7878df38e3eee97f1d1c58e80f3a4f8c Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 4 Apr 2019 16:35:40 -0400 Subject: [PATCH] Cascading auto-drops --- angel_orm_generator/CHANGELOG.md | 1 + .../lib/src/migration_generator.dart | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/angel_orm_generator/CHANGELOG.md b/angel_orm_generator/CHANGELOG.md index ac631ae4..b102cc56 100644 --- a/angel_orm_generator/CHANGELOG.md +++ b/angel_orm_generator/CHANGELOG.md @@ -3,6 +3,7 @@ * Handle cases where the class is not a `Model`. * Stop assuming things have `id`, etc. * Resolve a bug where the `indexType` of `@Column` annotations. would not be found. +* Add `cascade: true` to drops for hasOne/hasMany/ManyToMany migrations. # 2.0.0-dev.6 * Fix bug where an extra field would be inserted into joins and botch the result. diff --git a/angel_orm_generator/lib/src/migration_generator.dart b/angel_orm_generator/lib/src/migration_generator.dart index e0a246e4..abd1c027 100644 --- a/angel_orm_generator/lib/src/migration_generator.dart +++ b/angel_orm_generator/lib/src/migration_generator.dart @@ -237,8 +237,18 @@ class MigrationGenerator extends GeneratorForAnnotation { ..annotations.add(refer('override')) ..requiredParameters.add(_schemaParam) ..body = new Block((b) { - b.addExpression( - _schema.property('drop').call([literalString(ctx.tableName)])); + var named = {}; + + if (ctx.relations.values.any((r) => + r.type == RelationshipType.hasOne || + r.type == RelationshipType.hasMany || + r.isManyToMany)) { + named['cascade'] = literalTrue; + } + + b.addExpression(_schema + .property('drop') + .call([literalString(ctx.tableName)], named)); }); }); }