Open dshukertjr opened 1 month ago
I'm going through the get started guide and am getting stuck at the Object database mapping section.
The db related code seems to not be generated, and I am getting The getter 'db' isn't defined for the type 'Company'. error.
The getter 'db' isn't defined for the type 'Company'.
serverpod create mypod
cd mypod/mypod_server docker compose up --build --detach dart bin/main.dart --apply-migrations
mypod_server/lib/src/models/company.spy.yaml
class: Company table: company fields: name: String foundedDate: DateTime?
serverpod generate
mypod_server
serverpod create-migration
dart bin/main.dart --apply-migrations
mypod_flutter
await Company.db.insertRow(session, myCompany);
Here is what I have for mypod_client/lib/src/protocol/company.dart
mypod_client/lib/src/protocol/company.dart
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */ /* To generate run: "serverpod generate" */ // ignore_for_file: implementation_imports // ignore_for_file: library_private_types_in_public_api // ignore_for_file: non_constant_identifier_names // ignore_for_file: public_member_api_docs // ignore_for_file: type_literal_in_constant_pattern // ignore_for_file: use_super_parameters // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:serverpod_client/serverpod_client.dart' as _i1; abstract class Company implements _i1.SerializableModel { Company._({ this.id, required this.name, this.foundedDate, }); factory Company({ int? id, required String name, DateTime? foundedDate, }) = _CompanyImpl; factory Company.fromJson(Map<String, dynamic> jsonSerialization) { return Company( id: jsonSerialization['id'] as int?, name: jsonSerialization['name'] as String, foundedDate: jsonSerialization['foundedDate'] == null ? null : _i1.DateTimeJsonExtension.fromJson( jsonSerialization['foundedDate']), ); } /// The database id, set if the object has been inserted into the /// database or if it has been fetched from the database. Otherwise, /// the id will be null. int? id; String name; DateTime? foundedDate; Company copyWith({ int? id, String? name, DateTime? foundedDate, }); @override Map<String, dynamic> toJson() { return { if (id != null) 'id': id, 'name': name, if (foundedDate != null) 'foundedDate': foundedDate?.toJson(), }; } @override String toString() { return _i1.SerializationManager.encode(this); } } class _Undefined {} class _CompanyImpl extends Company { _CompanyImpl({ int? id, required String name, DateTime? foundedDate, }) : super._( id: id, name: name, foundedDate: foundedDate, ); @override Company copyWith({ Object? id = _Undefined, String? name, Object? foundedDate = _Undefined, }) { return Company( id: id is int? ? id : this.id, name: name ?? this.name, foundedDate: foundedDate is DateTime? ? foundedDate : this.foundedDate, ); } }
I'm going through the get started guide and am getting stuck at the Object database mapping section.
The db related code seems to not be generated, and I am getting
The getter 'db' isn't defined for the type 'Company'.
error.Steps to reproduce
serverpod create mypod
mypod_server/lib/src/models/company.spy.yaml
file with the following:serverpod generate
insidemypod_server
serverpod create-migration
insidemypod_server
dart bin/main.dart --apply-migrations
mypod_flutter
app and observe the error.Here is what I have for
mypod_client/lib/src/protocol/company.dart