File tree Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Original file line number Diff line number Diff line change 1
1
import 'package:json_api/src/document/identifier.dart' ;
2
2
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' ;
5
3
6
4
class ToMany extends Relationship {
7
5
ToMany (Iterable <Identifier > identifiers) {
@@ -18,10 +16,4 @@ class ToMany extends Relationship {
18
16
19
17
@override
20
18
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)));
27
19
}
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ void main() {
60
60
expect (fetchedAuthor? .attributes['name' ], 'Alice' );
61
61
62
62
final fetchedComment =
63
- fetchedPost.many ('comments' )! . findIn ( response.included).single;
63
+ find ( fetchedPost.many ('comments' )! , response.included).single;
64
64
expect (fetchedComment.attributes['text' ], 'Hi Alice' );
65
65
});
66
66
@@ -142,16 +142,12 @@ void main() {
142
142
Include (['comments' ])
143
143
]).then ((r) {
144
144
expect (
145
- r.resource
146
- .many ('comments' )!
147
- .findIn (r.included)
145
+ find (r.resource.many ('comments' )! , r.included)
148
146
.single
149
147
.attributes['text' ],
150
148
'Secret comment' );
151
149
expect (
152
- r.resource
153
- .many ('comments' )!
154
- .findIn (r.included)
150
+ find (r.resource.many ('comments' )! , r.included)
155
151
.single
156
152
.attributes['text' ],
157
153
'Secret comment' );
@@ -179,3 +175,10 @@ void main() {
179
175
});
180
176
});
181
177
}
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)));
You can’t perform that action at this time.
0 commit comments