Add joinType to Relationship
This commit is contained in:
parent
2533902e71
commit
fdac775e41
2 changed files with 25 additions and 9 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import 'annotations.dart';
|
||||||
|
|
||||||
abstract class RelationshipType {
|
abstract class RelationshipType {
|
||||||
static const int hasMany = 0;
|
static const int hasMany = 0;
|
||||||
static const int hasOne = 1;
|
static const int hasOne = 1;
|
||||||
|
@ -11,12 +13,14 @@ class Relationship {
|
||||||
final String foreignKey;
|
final String foreignKey;
|
||||||
final String foreignTable;
|
final String foreignTable;
|
||||||
final bool cascadeOnDelete;
|
final bool cascadeOnDelete;
|
||||||
|
final JoinType joinType;
|
||||||
|
|
||||||
const Relationship(this.type,
|
const Relationship(this.type,
|
||||||
{this.localKey,
|
{this.localKey,
|
||||||
this.foreignKey,
|
this.foreignKey,
|
||||||
this.foreignTable,
|
this.foreignTable,
|
||||||
this.cascadeOnDelete});
|
this.cascadeOnDelete,
|
||||||
|
this.joinType});
|
||||||
}
|
}
|
||||||
|
|
||||||
class HasMany extends Relationship {
|
class HasMany extends Relationship {
|
||||||
|
@ -24,12 +28,14 @@ class HasMany extends Relationship {
|
||||||
{String localKey,
|
{String localKey,
|
||||||
String foreignKey,
|
String foreignKey,
|
||||||
String foreignTable,
|
String foreignTable,
|
||||||
bool cascadeOnDelete = false})
|
bool cascadeOnDelete = false,
|
||||||
|
JoinType joinType = JoinType.left})
|
||||||
: super(RelationshipType.hasMany,
|
: super(RelationshipType.hasMany,
|
||||||
localKey: localKey,
|
localKey: localKey,
|
||||||
foreignKey: foreignKey,
|
foreignKey: foreignKey,
|
||||||
foreignTable: foreignTable,
|
foreignTable: foreignTable,
|
||||||
cascadeOnDelete: cascadeOnDelete == true);
|
cascadeOnDelete: cascadeOnDelete == true,
|
||||||
|
joinType: joinType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const HasMany hasMany = HasMany();
|
const HasMany hasMany = HasMany();
|
||||||
|
@ -39,22 +45,29 @@ class HasOne extends Relationship {
|
||||||
{String localKey,
|
{String localKey,
|
||||||
String foreignKey,
|
String foreignKey,
|
||||||
String foreignTable,
|
String foreignTable,
|
||||||
bool cascadeOnDelete = false})
|
bool cascadeOnDelete = false,
|
||||||
|
JoinType joinType = JoinType.left})
|
||||||
: super(RelationshipType.hasOne,
|
: super(RelationshipType.hasOne,
|
||||||
localKey: localKey,
|
localKey: localKey,
|
||||||
foreignKey: foreignKey,
|
foreignKey: foreignKey,
|
||||||
foreignTable: foreignTable,
|
foreignTable: foreignTable,
|
||||||
cascadeOnDelete: cascadeOnDelete == true);
|
cascadeOnDelete: cascadeOnDelete == true,
|
||||||
|
joinType: joinType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const HasOne hasOne = HasOne();
|
const HasOne hasOne = HasOne();
|
||||||
|
|
||||||
class BelongsTo extends Relationship {
|
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,
|
: super(RelationshipType.belongsTo,
|
||||||
localKey: localKey,
|
localKey: localKey,
|
||||||
foreignKey: foreignKey,
|
foreignKey: foreignKey,
|
||||||
foreignTable: foreignTable);
|
foreignTable: foreignTable,
|
||||||
|
joinType: joinType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const BelongsTo belongsTo = BelongsTo();
|
const BelongsTo belongsTo = BelongsTo();
|
||||||
|
@ -66,11 +79,13 @@ class ManyToMany extends Relationship {
|
||||||
{String localKey,
|
{String localKey,
|
||||||
String foreignKey,
|
String foreignKey,
|
||||||
String foreignTable,
|
String foreignTable,
|
||||||
bool cascadeOnDelete = false})
|
bool cascadeOnDelete = false,
|
||||||
|
JoinType joinType = JoinType.left})
|
||||||
: super(
|
: super(
|
||||||
RelationshipType.hasMany, // Many-to-Many is actually just a hasMany
|
RelationshipType.hasMany, // Many-to-Many is actually just a hasMany
|
||||||
localKey: localKey,
|
localKey: localKey,
|
||||||
foreignKey: foreignKey,
|
foreignKey: foreignKey,
|
||||||
foreignTable: foreignTable,
|
foreignTable: foreignTable,
|
||||||
cascadeOnDelete: cascadeOnDelete == true);
|
cascadeOnDelete: cascadeOnDelete == true,
|
||||||
|
joinType: joinType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns values on true subquery', () async {
|
test('returns values on true subquery', () async {
|
||||||
|
printSeparator('True subquery test');
|
||||||
var query = BookQuery()..author.where.name.like('%Rowling%');
|
var query = BookQuery()..author.where.name.like('%Rowling%');
|
||||||
expect(await query.get(executor), [deathlyHallows]);
|
expect(await query.get(executor), [deathlyHallows]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue