2017-07-06 20:14:26 +00:00
|
|
|
abstract class RelationshipType {
|
2018-08-24 12:30:38 +00:00
|
|
|
static const int hasMany = 0;
|
|
|
|
static const int hasOne = 1;
|
|
|
|
static const int belongsTo = 2;
|
|
|
|
static const int belongsToMany = 3;
|
2017-07-06 20:14:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 22:40:23 +00:00
|
|
|
class Relationship {
|
2017-07-06 20:14:26 +00:00
|
|
|
final int type;
|
2017-06-18 22:40:23 +00:00
|
|
|
final String localKey;
|
|
|
|
final String foreignKey;
|
|
|
|
final String foreignTable;
|
|
|
|
final bool cascadeOnDelete;
|
|
|
|
|
2017-07-06 20:14:26 +00:00
|
|
|
const Relationship(this.type,
|
2017-06-18 22:40:23 +00:00
|
|
|
{this.localKey,
|
|
|
|
this.foreignKey,
|
|
|
|
this.foreignTable,
|
|
|
|
this.cascadeOnDelete});
|
|
|
|
}
|
|
|
|
|
|
|
|
class HasMany extends Relationship {
|
|
|
|
const HasMany(
|
2017-06-24 21:21:32 +00:00
|
|
|
{String localKey: 'id',
|
2017-06-18 22:40:23 +00:00
|
|
|
String foreignKey,
|
|
|
|
String foreignTable,
|
|
|
|
bool cascadeOnDelete: false})
|
2018-08-24 12:30:38 +00:00
|
|
|
: super(RelationshipType.hasMany,
|
2017-06-18 22:40:23 +00:00
|
|
|
localKey: localKey,
|
|
|
|
foreignKey: foreignKey,
|
|
|
|
foreignTable: foreignTable,
|
|
|
|
cascadeOnDelete: cascadeOnDelete == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const HasMany hasMany = const HasMany();
|
|
|
|
|
|
|
|
class HasOne extends Relationship {
|
|
|
|
const HasOne(
|
2017-06-24 21:21:32 +00:00
|
|
|
{String localKey: 'id',
|
2017-06-18 22:40:23 +00:00
|
|
|
String foreignKey,
|
|
|
|
String foreignTable,
|
|
|
|
bool cascadeOnDelete: false})
|
2018-08-24 12:30:38 +00:00
|
|
|
: super(RelationshipType.hasOne,
|
2017-06-18 22:40:23 +00:00
|
|
|
localKey: localKey,
|
|
|
|
foreignKey: foreignKey,
|
|
|
|
foreignTable: foreignTable,
|
|
|
|
cascadeOnDelete: cascadeOnDelete == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const HasOne hasOne = const HasOne();
|
|
|
|
|
|
|
|
class BelongsTo extends Relationship {
|
2017-06-24 21:21:32 +00:00
|
|
|
const BelongsTo(
|
|
|
|
{String localKey: 'id', String foreignKey, String foreignTable})
|
2018-08-24 12:30:38 +00:00
|
|
|
: super(RelationshipType.belongsTo,
|
2017-06-18 22:40:23 +00:00
|
|
|
localKey: localKey,
|
|
|
|
foreignKey: foreignKey,
|
|
|
|
foreignTable: foreignTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BelongsTo belongsTo = const BelongsTo();
|
2017-07-15 18:17:45 +00:00
|
|
|
|
|
|
|
class BelongsToMany extends Relationship {
|
|
|
|
const BelongsToMany(
|
|
|
|
{String localKey: 'id', String foreignKey, String foreignTable})
|
2018-08-24 12:30:38 +00:00
|
|
|
: super(RelationshipType.belongsToMany,
|
2017-07-15 18:17:45 +00:00
|
|
|
localKey: localKey,
|
|
|
|
foreignKey: foreignKey,
|
|
|
|
foreignTable: foreignTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BelongsToMany belongsToMany = const BelongsToMany();
|