Skip to content

Commit 4e30de5

Browse files
authored
fix: Prevent update from clearing out implicit fields. (serverpod#3360)
1 parent 5b5f0c6 commit 4e30de5

File tree

27 files changed

+16365
-1538
lines changed

27 files changed

+16365
-1538
lines changed

packages/serverpod/lib/src/database/adapters/postgres/database_connection.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class DatabaseConnection {
183183

184184
var table = rows.first.table;
185185

186-
var selectedColumns = (columns ?? table.columns).toSet();
186+
var selectedColumns = (columns ?? table.managedColumns).toSet();
187187

188188
if (columns != null) {
189189
_validateColumnsExists(selectedColumns, table.columns.toSet());

packages/serverpod/lib/src/database/concepts/table.dart

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Table<T_ID> {
2525
/// List of [Column] used by the table.
2626
List<Column> get columns => [id];
2727

28+
/// List of [Column] that are managed by this table.
29+
/// This is mostly used to exclude columns created by implicit relations.
30+
List<Column> get managedColumns => columns;
31+
2832
/// Query prefix for [Column]s of the table.
2933
String get queryPrefix {
3034
return tableRelation?.relationQueryAlias ?? tableName;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
2+
/* To generate run: "serverpod generate" */
3+
4+
// ignore_for_file: implementation_imports
5+
// ignore_for_file: library_private_types_in_public_api
6+
// ignore_for_file: non_constant_identifier_names
7+
// ignore_for_file: public_member_api_docs
8+
// ignore_for_file: type_literal_in_constant_pattern
9+
// ignore_for_file: use_super_parameters
10+
11+
// ignore_for_file: no_leading_underscores_for_library_prefixes
12+
import 'package:serverpod_client/serverpod_client.dart' as _i1;
13+
import '../../../models_with_relations/one_to_many/implicit/chapter.dart'
14+
as _i2;
15+
16+
abstract class Book implements _i1.SerializableModel {
17+
Book._({
18+
this.id,
19+
required this.title,
20+
this.chapters,
21+
});
22+
23+
factory Book({
24+
int? id,
25+
required String title,
26+
List<_i2.Chapter>? chapters,
27+
}) = _BookImpl;
28+
29+
factory Book.fromJson(Map<String, dynamic> jsonSerialization) {
30+
return Book(
31+
id: jsonSerialization['id'] as int?,
32+
title: jsonSerialization['title'] as String,
33+
chapters: (jsonSerialization['chapters'] as List?)
34+
?.map((e) => _i2.Chapter.fromJson((e as Map<String, dynamic>)))
35+
.toList(),
36+
);
37+
}
38+
39+
/// The database id, set if the object has been inserted into the
40+
/// database or if it has been fetched from the database. Otherwise,
41+
/// the id will be null.
42+
int? id;
43+
44+
String title;
45+
46+
List<_i2.Chapter>? chapters;
47+
48+
/// Returns a shallow copy of this [Book]
49+
/// with some or all fields replaced by the given arguments.
50+
@_i1.useResult
51+
Book copyWith({
52+
int? id,
53+
String? title,
54+
List<_i2.Chapter>? chapters,
55+
});
56+
@override
57+
Map<String, dynamic> toJson() {
58+
return {
59+
if (id != null) 'id': id,
60+
'title': title,
61+
if (chapters != null)
62+
'chapters': chapters?.toJson(valueToJson: (v) => v.toJson()),
63+
};
64+
}
65+
66+
@override
67+
String toString() {
68+
return _i1.SerializationManager.encode(this);
69+
}
70+
}
71+
72+
class _Undefined {}
73+
74+
class _BookImpl extends Book {
75+
_BookImpl({
76+
int? id,
77+
required String title,
78+
List<_i2.Chapter>? chapters,
79+
}) : super._(
80+
id: id,
81+
title: title,
82+
chapters: chapters,
83+
);
84+
85+
/// Returns a shallow copy of this [Book]
86+
/// with some or all fields replaced by the given arguments.
87+
@_i1.useResult
88+
@override
89+
Book copyWith({
90+
Object? id = _Undefined,
91+
String? title,
92+
Object? chapters = _Undefined,
93+
}) {
94+
return Book(
95+
id: id is int? ? id : this.id,
96+
title: title ?? this.title,
97+
chapters: chapters is List<_i2.Chapter>?
98+
? chapters
99+
: this.chapters?.map((e0) => e0.copyWith()).toList(),
100+
);
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
2+
/* To generate run: "serverpod generate" */
3+
4+
// ignore_for_file: implementation_imports
5+
// ignore_for_file: library_private_types_in_public_api
6+
// ignore_for_file: non_constant_identifier_names
7+
// ignore_for_file: public_member_api_docs
8+
// ignore_for_file: type_literal_in_constant_pattern
9+
// ignore_for_file: use_super_parameters
10+
11+
// ignore_for_file: no_leading_underscores_for_library_prefixes
12+
import 'package:serverpod_client/serverpod_client.dart' as _i1;
13+
14+
abstract class Chapter implements _i1.SerializableModel {
15+
Chapter._({
16+
this.id,
17+
required this.title,
18+
});
19+
20+
factory Chapter({
21+
int? id,
22+
required String title,
23+
}) = _ChapterImpl;
24+
25+
factory Chapter.fromJson(Map<String, dynamic> jsonSerialization) {
26+
return Chapter(
27+
id: jsonSerialization['id'] as int?,
28+
title: jsonSerialization['title'] as String,
29+
);
30+
}
31+
32+
/// The database id, set if the object has been inserted into the
33+
/// database or if it has been fetched from the database. Otherwise,
34+
/// the id will be null.
35+
int? id;
36+
37+
String title;
38+
39+
/// Returns a shallow copy of this [Chapter]
40+
/// with some or all fields replaced by the given arguments.
41+
@_i1.useResult
42+
Chapter copyWith({
43+
int? id,
44+
String? title,
45+
});
46+
@override
47+
Map<String, dynamic> toJson() {
48+
return {
49+
if (id != null) 'id': id,
50+
'title': title,
51+
};
52+
}
53+
54+
@override
55+
String toString() {
56+
return _i1.SerializationManager.encode(this);
57+
}
58+
}
59+
60+
class _Undefined {}
61+
62+
class _ChapterImpl extends Chapter {
63+
_ChapterImpl({
64+
int? id,
65+
required String title,
66+
}) : super._(
67+
id: id,
68+
title: title,
69+
);
70+
71+
/// Returns a shallow copy of this [Chapter]
72+
/// with some or all fields replaced by the given arguments.
73+
@_i1.useResult
74+
@override
75+
Chapter copyWith({
76+
Object? id = _Undefined,
77+
String? title,
78+
}) {
79+
return Chapter(
80+
id: id is int? ? id : this.id,
81+
title: title ?? this.title,
82+
);
83+
}
84+
}

0 commit comments

Comments
 (0)