Skip to content

Commit

Permalink
all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
codekeyz committed Apr 17, 2024
1 parent 6b8bdd8 commit 8c6f2df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/src/models/article/article.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../user/user.dart';
part 'article.g.dart';

@Table('articles', converters: [dateTimeConverter, booleanConverter])
class Article extends Entity {
class Article extends Entity<Article> {
@primaryKey
final int id;

Expand Down Expand Up @@ -33,6 +33,8 @@ class Article extends Entity {
required this.updatedAt,
});

BelongsTo<Article, User> get owner => belongsTo<User>();

Map<String, dynamic> toJson() => <String, dynamic>{
'id': id,
'createdAt': createdAt.toIso8601String(),
Expand Down
6 changes: 4 additions & 2 deletions lib/src/models/user/user.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:yaroorm/yaroorm.dart';

import '../article/article.dart';

part 'user.g.dart';

@Table('users')
class User extends Entity {
class User extends Entity<User> {
@primaryKey
final int id;

Expand All @@ -28,7 +30,7 @@ class User extends Entity {
required this.updatedAt,
});

// HasMany<Article> get articles => hasMany<Article>();
HasMany<User, Article> get articles => hasMany<Article>();

Map<String, dynamic> toJson() => <String, dynamic>{
'id': id,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55"
sha256: "6d691edde054969f0e0f26abb1b30834b5138b963793e56f69d3a9a4435e6352"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.0"
dotenv:
dependency: transitive
description:
Expand Down
5 changes: 4 additions & 1 deletion test/backend_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ void main() {

DB.init(orm.config);

Query.addTypeDef<User>(userTypeData);
Query.addTypeDef<Article>(articleTypeData);

late Spookie testAgent;

setUpAll(() async {
Expand Down Expand Up @@ -183,7 +186,7 @@ void main() {
authCookie = result.headers[HttpHeaders.setCookieHeader];
expect(authCookie, isNotNull);

await ArticleQuery.where((article) => article.ownerId(currentUser!.id)).delete();
await currentUser!.articles.delete();
});

group('Users', () {
Expand Down

0 comments on commit 8c6f2df

Please sign in to comment.