Cascading auto-drops

This commit is contained in:
Tobe O 2019-04-04 16:35:40 -04:00
parent 00cffcf200
commit 4aed69fb78
2 changed files with 13 additions and 2 deletions

View file

@ -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.

View file

@ -237,8 +237,18 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
..annotations.add(refer('override'))
..requiredParameters.add(_schemaParam)
..body = new Block((b) {
b.addExpression(
_schema.property('drop').call([literalString(ctx.tableName)]));
var named = <String, Expression>{};
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));
});
});
}