Skip to content

Commit 4306163

Browse files
committed
Remove ToMany.findIn
1 parent 3c54ccd commit 4306163

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

lib/src/document/many.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:json_api/src/document/identifier.dart';
22
import 'package:json_api/src/document/relationship.dart';
3-
import 'package:json_api/src/document/resource.dart';
4-
import 'package:json_api/src/document/resource_collection.dart';
53

64
class ToMany extends Relationship {
75
ToMany(Iterable<Identifier> identifiers) {
@@ -18,10 +16,4 @@ class ToMany extends Relationship {
1816

1917
@override
2018
Iterator<Identifier> get iterator => _ids.iterator;
21-
22-
/// Finds the referenced elements which are found in the [collection].
23-
/// The resulting [Iterable] may contain fewer elements than referred by the
24-
/// relationship if the [collection] does not have all of them.
25-
Iterable<Resource> findIn(ResourceCollection collection) => collection.where(
26-
(resource) => any((identifier) => identifier.identifies(resource)));
2719
}

test/contract/crud_test.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void main() {
6060
expect(fetchedAuthor?.attributes['name'], 'Alice');
6161

6262
final fetchedComment =
63-
fetchedPost.many('comments')!.findIn(response.included).single;
63+
find(fetchedPost.many('comments')!, response.included).single;
6464
expect(fetchedComment.attributes['text'], 'Hi Alice');
6565
});
6666

@@ -142,16 +142,12 @@ void main() {
142142
Include(['comments'])
143143
]).then((r) {
144144
expect(
145-
r.resource
146-
.many('comments')!
147-
.findIn(r.included)
145+
find(r.resource.many('comments')!, r.included)
148146
.single
149147
.attributes['text'],
150148
'Secret comment');
151149
expect(
152-
r.resource
153-
.many('comments')!
154-
.findIn(r.included)
150+
find(r.resource.many('comments')!, r.included)
155151
.single
156152
.attributes['text'],
157153
'Secret comment');
@@ -179,3 +175,10 @@ void main() {
179175
});
180176
});
181177
}
178+
179+
/// Finds the referenced elements which are found in the [collection].
180+
/// The resulting [Iterable] may contain fewer elements than referred by the
181+
/// relationship if the [collection] does not have all of them.
182+
Iterable<Resource> find(ToMany many, ResourceCollection collection) =>
183+
collection.where((resource) =>
184+
many.any((identifier) => identifier.identifies(resource)));

0 commit comments

Comments
 (0)