From fdac775e41f1cdc68b71b3f3aa8954f600acd19a Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 9 Oct 2019 11:18:58 -0400 Subject: [PATCH] Add joinType to Relationship --- angel_orm/lib/src/relations.dart | 33 +++++++++++++++------ angel_orm_test/lib/src/belongs_to_test.dart | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/angel_orm/lib/src/relations.dart b/angel_orm/lib/src/relations.dart index 0d736925..5edeed39 100644 --- a/angel_orm/lib/src/relations.dart +++ b/angel_orm/lib/src/relations.dart @@ -1,3 +1,5 @@ +import 'annotations.dart'; + abstract class RelationshipType { static const int hasMany = 0; static const int hasOne = 1; @@ -11,12 +13,14 @@ class Relationship { final String foreignKey; final String foreignTable; final bool cascadeOnDelete; + final JoinType joinType; const Relationship(this.type, {this.localKey, this.foreignKey, this.foreignTable, - this.cascadeOnDelete}); + this.cascadeOnDelete, + this.joinType}); } class HasMany extends Relationship { @@ -24,12 +28,14 @@ class HasMany extends Relationship { {String localKey, String foreignKey, String foreignTable, - bool cascadeOnDelete = false}) + bool cascadeOnDelete = false, + JoinType joinType = JoinType.left}) : super(RelationshipType.hasMany, localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable, - cascadeOnDelete: cascadeOnDelete == true); + cascadeOnDelete: cascadeOnDelete == true, + joinType: joinType); } const HasMany hasMany = HasMany(); @@ -39,22 +45,29 @@ class HasOne extends Relationship { {String localKey, String foreignKey, String foreignTable, - bool cascadeOnDelete = false}) + bool cascadeOnDelete = false, + JoinType joinType = JoinType.left}) : super(RelationshipType.hasOne, localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable, - cascadeOnDelete: cascadeOnDelete == true); + cascadeOnDelete: cascadeOnDelete == true, + joinType: joinType); } const HasOne hasOne = HasOne(); class BelongsTo extends Relationship { - const BelongsTo({String localKey, String foreignKey, String foreignTable}) + const BelongsTo( + {String localKey, + String foreignKey, + String foreignTable, + JoinType joinType = JoinType.left}) : super(RelationshipType.belongsTo, localKey: localKey, foreignKey: foreignKey, - foreignTable: foreignTable); + foreignTable: foreignTable, + joinType: joinType); } const BelongsTo belongsTo = BelongsTo(); @@ -66,11 +79,13 @@ class ManyToMany extends Relationship { {String localKey, String foreignKey, String foreignTable, - bool cascadeOnDelete = false}) + bool cascadeOnDelete = false, + JoinType joinType = JoinType.left}) : super( RelationshipType.hasMany, // Many-to-Many is actually just a hasMany localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable, - cascadeOnDelete: cascadeOnDelete == true); + cascadeOnDelete: cascadeOnDelete == true, + joinType: joinType); } diff --git a/angel_orm_test/lib/src/belongs_to_test.dart b/angel_orm_test/lib/src/belongs_to_test.dart index bd63c2e0..09342317 100644 --- a/angel_orm_test/lib/src/belongs_to_test.dart +++ b/angel_orm_test/lib/src/belongs_to_test.dart @@ -159,6 +159,7 @@ belongsToTests(FutureOr Function() createExecutor, }); test('returns values on true subquery', () async { + printSeparator('True subquery test'); var query = BookQuery()..author.where.name.like('%Rowling%'); expect(await query.get(executor), [deathlyHallows]); });