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;
|
2019-01-07 18:22:12 +00:00
|
|
|
static const int manyToMany = 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(
|
2019-04-03 09:57:27 +00:00
|
|
|
{String localKey,
|
2017-06-18 22:40:23 +00:00
|
|
|
String foreignKey,
|
|
|
|
String foreignTable,
|
2019-04-02 23:19:01 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
const HasMany hasMany = HasMany();
|
2017-06-18 22:40:23 +00:00
|
|
|
|
|
|
|
class HasOne extends Relationship {
|
|
|
|
const HasOne(
|
2019-04-03 09:57:27 +00:00
|
|
|
{String localKey,
|
2017-06-18 22:40:23 +00:00
|
|
|
String foreignKey,
|
|
|
|
String foreignTable,
|
2019-04-02 23:19:01 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
const HasOne hasOne = HasOne();
|
2017-06-18 22:40:23 +00:00
|
|
|
|
|
|
|
class BelongsTo extends Relationship {
|
2018-12-03 23:13:11 +00:00
|
|
|
const BelongsTo({String localKey, 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);
|
|
|
|
}
|
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
const BelongsTo belongsTo = BelongsTo();
|
2019-01-07 18:22:12 +00:00
|
|
|
|
|
|
|
class ManyToMany extends Relationship {
|
2019-04-02 23:05:13 +00:00
|
|
|
final Type through;
|
|
|
|
|
|
|
|
const ManyToMany(this.through,
|
2019-04-03 09:57:27 +00:00
|
|
|
{String localKey,
|
2019-01-07 18:22:12 +00:00
|
|
|
String foreignKey,
|
|
|
|
String foreignTable,
|
2019-04-02 23:19:01 +00:00
|
|
|
bool cascadeOnDelete = false})
|
|
|
|
: super(
|
|
|
|
RelationshipType.hasMany, // Many-to-Many is actually just a hasMany
|
2019-01-07 18:22:12 +00:00
|
|
|
localKey: localKey,
|
|
|
|
foreignKey: foreignKey,
|
|
|
|
foreignTable: foreignTable,
|
|
|
|
cascadeOnDelete: cascadeOnDelete == true);
|
|
|
|
}
|