Skip to content

Commit 4b30d9f

Browse files
committed
Add Resource.lid
1 parent 1423a68 commit 4b30d9f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/src/document/new_resource.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import 'package:json_api/src/document/resource_properties.dart';
22

33
/// A set of properties for a to-be-created resource which does not have the id yet.
44
class NewResource with ResourceProperties {
5-
NewResource(this.type, {this.id});
5+
NewResource(this.type, {this.id, this.lid});
66

77
/// Resource type
88
final String type;
99

10-
/// Nullable. Resource id.
10+
/// Resource id.
1111
final String? id;
1212

13+
/// Local resource id.
14+
final String? lid;
15+
1316
Map<String, Object> toJson() => {
1417
'type': type,
1518
if (id != null) 'id': id!,
19+
if (lid != null) 'lid': lid!,
1620
if (attributes.isNotEmpty) 'attributes': attributes,
1721
if (relationships.isNotEmpty) 'relationships': relationships,
1822
if (meta.isNotEmpty) 'meta': meta,

test/unit/document/new_resource_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void main() {
1010
jsonEncode({'type': 'test_type'}));
1111

1212
expect(
13-
jsonEncode(NewResource('test_type')
13+
jsonEncode(NewResource('test_type', id: 'test_id', lid: 'test_lid')
1414
..meta['foo'] = [42]
1515
..attributes['color'] = 'green'
1616
..relationships['one'] =
@@ -21,6 +21,8 @@ void main() {
2121
..meta['many'] = 1)),
2222
jsonEncode({
2323
'type': 'test_type',
24+
'id': 'test_id',
25+
'lid': 'test_lid',
2426
'attributes': {'color': 'green'},
2527
'relationships': {
2628
'one': {

0 commit comments

Comments
 (0)