File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -5,23 +5,23 @@ import 'package:json_api/src/document/resource_collection.dart';
5
5
6
6
class ToMany extends Relationship {
7
7
ToMany (Iterable <Identifier > identifiers) {
8
- for (var id in identifiers) {
9
- _map[id.key] = id;
10
- }
8
+ _ids.addAll (identifiers);
11
9
}
12
10
13
- final _map = < String , Identifier > {} ;
11
+ final _ids = < Identifier > [] ;
14
12
15
13
@override
16
- Map <String , Object > toJson () =>
17
- {'data' : _map.values.toList (), ...super .toJson ()};
14
+ Map <String , Object > toJson () => {
15
+ 'data' : [..._ids],
16
+ ...super .toJson ()
17
+ };
18
18
19
19
@override
20
- Iterator <Identifier > get iterator => _map.values .iterator;
20
+ Iterator <Identifier > get iterator => _ids .iterator;
21
21
22
22
/// Finds the referenced elements which are found in the [collection] .
23
23
/// The resulting [Iterable] may contain fewer elements than referred by the
24
24
/// relationship if the [collection] does not have all of them.
25
- Iterable <Resource > findIn (ResourceCollection collection) =>
26
- _map.keys. map ((key ) => collection[key]). whereType ( );
25
+ Iterable <Resource > findIn (ResourceCollection collection) => collection. where (
26
+ (resource ) => any ((identifier) => identifier. identifies (resource)) );
27
27
}
You can’t perform that action at this time.
0 commit comments