diff --git a/angel_orm/CHANGELOG.md b/angel_orm/CHANGELOG.md index f7f4c220..3a624ab8 100644 --- a/angel_orm/CHANGELOG.md +++ b/angel_orm/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.0.0-alpha+7 +* Added a `@belongsToMany` annotation class. +* Resolved [#20](https://github.com/angel-dart/orm/issues/20). The +`PostgreSQLConnectionPool` keeps track of which connections have been opened now. + # 1.0.0-alpha+6 * `DateTimeSqlExpressionBuilder` will no longer automatically insert quotation marks around names. diff --git a/angel_orm/lib/src/pool.dart b/angel_orm/lib/src/pool.dart index 9cdb0722..da77b854 100644 --- a/angel_orm/lib/src/pool.dart +++ b/angel_orm/lib/src/pool.dart @@ -38,7 +38,10 @@ class PostgreSQLConnectionPool { var connection = _connections[_index++]; if (_index >= _connections.length) _index = 0; - if (!_opened.contains(connection.hashCode)) await connection.open(); + if (!_opened.contains(connection.hashCode)) { + await connection.open(); + _opened.add(connection.hashCode); + } return connection; } diff --git a/angel_orm/lib/src/relations.dart b/angel_orm/lib/src/relations.dart index 93677342..8eb57c26 100644 --- a/angel_orm/lib/src/relations.dart +++ b/angel_orm/lib/src/relations.dart @@ -2,6 +2,7 @@ abstract class RelationshipType { static const int HAS_MANY = 0; static const int HAS_ONE = 1; static const int BELONGS_TO = 2; + static const int BELONGS_TO_MANY = 3; } class Relationship { @@ -24,7 +25,7 @@ class HasMany extends Relationship { String foreignKey, String foreignTable, bool cascadeOnDelete: false}) - : super(0, + : super(RelationshipType.HAS_MANY, localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable, @@ -39,7 +40,7 @@ class HasOne extends Relationship { String foreignKey, String foreignTable, bool cascadeOnDelete: false}) - : super(1, + : super(RelationshipType.HAS_ONE, localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable, @@ -51,10 +52,21 @@ const HasOne hasOne = const HasOne(); class BelongsTo extends Relationship { const BelongsTo( {String localKey: 'id', String foreignKey, String foreignTable}) - : super(2, + : super(RelationshipType.BELONGS_TO, localKey: localKey, foreignKey: foreignKey, foreignTable: foreignTable); } const BelongsTo belongsTo = const BelongsTo(); + +class BelongsToMany extends Relationship { + const BelongsToMany( + {String localKey: 'id', String foreignKey, String foreignTable}) + : super(RelationshipType.BELONGS_TO_MANY, + localKey: localKey, + foreignKey: foreignKey, + foreignTable: foreignTable); +} + +const BelongsToMany belongsToMany = const BelongsToMany(); diff --git a/angel_orm/pubspec.yaml b/angel_orm/pubspec.yaml index 9cbc0b23..2680fcce 100644 --- a/angel_orm/pubspec.yaml +++ b/angel_orm/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm -version: 1.0.0-alpha+6 +version: 1.0.0-alpha+7 description: Runtime support for Angel's ORM. author: Tobe O homepage: https://github.com/angel-dart/orm