Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override id type? #91

Open
kevinelliott opened this issue Dec 31, 2022 · 8 comments
Open

How to override id type? #91

kevinelliott opened this issue Dec 31, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@kevinelliott
Copy link
Contributor

kevinelliott commented Dec 31, 2022

For ORM model, how do you override the id type to be UUID (String)? There is some stuff that forces id as int for query, and this is problematic.

@dukefirehawk dukefirehawk added the bug Something isn't working label Dec 31, 2022
@dukefirehawk
Copy link
Collaborator

I think this could be a bug by looking at the generated code when id is String. The primary key is assumed to be auto generated numeric field in the where clause and table creation. Will issue a fix for this.

@kevinelliott
Copy link
Contributor Author

Great, thanks @dukefirehawk !

@dukefirehawk
Copy link
Collaborator

@kevinelliott Have you tried the following annotation?

@PrimaryKey(columnType: ColumnType.varChar)
String? get id;

Take a look at email_indexed.dart in the angel_orm_test package. Let us know if this works.

@dukefirehawk dukefirehawk self-assigned this Jan 2, 2023
@kevinelliott
Copy link
Contributor Author

@dukefirehawk Yes, when I try that, I get:

lib/marine/orm/managers/voyage_manager.dart:60:33: Error: Can't use 'id' because it is declared more than once.
      ..where!.id.equals(voyage.id!)
                                ^^
lib/marine/orm/managers/voyage_manager.dart:60:33: Error: The getter 'id' isn't defined for the class 'Voyage'.
 - 'Voyage' is from 'package:aggregation_server/marine/orm/models/voyage.dart' ('lib/marine/orm/models/voyage.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'id'.
      ..where!.id.equals(voyage.id!)
                                ^^
lib/marine/orm/managers/voyage_position_manager.dart:39:27: Error: Can't use 'id' because it is declared more than once.
      ..voyageId = voyage.id
                          ^^
lib/marine/orm/managers/voyage_position_manager.dart:39:27: Error: The getter 'id' isn't defined for the class 'Voyage'.
 - 'Voyage' is from 'package:aggregation_server/marine/orm/models/voyage.dart' ('lib/marine/orm/models/voyage.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'id'.
      ..voyageId = voyage.id
                          ^^
lib/marine/orm/models/voyage.g.dart:322:12: Error: Duplicated parameter name 'id'.
      this.id,
           ^^
lib/marine/orm/models/voyage.g.dart:319:13: Context: Other parameter named 'id'.
      {this.id,
            ^^
lib/marine/orm/models/voyage.g.dart:349:11: Error: 'id' is already declared in this scope.
  String? id;
          ^^
lib/marine/orm/models/voyage.g.dart:338:11: Context: Previous declaration of 'id'.
  String? id;
          ^^
lib/marine/orm/models/voyage.g.dart:391:15: Error: Duplicated parameter name 'id'.
      String? id,
              ^^
lib/marine/orm/models/voyage.g.dart:388:16: Context: Other parameter named 'id'.
      {String? id,
               ^^
lib/marine/orm/models/voyage.g.dart:608:23: Error: 'id' is already declared in this scope.
  static const String id = 'id';
                      ^^
lib/marine/orm/models/voyage.g.dart:602:23: Context: Previous declaration of 'id'.
  static const String id = 'id';
                      ^^
lib/marine/orm/models/voyage.g.dart:587:5: Error: Can't use 'id' because it is declared more than once.
    id,
    ^
lib/marine/orm/models/voyage.g.dart:584:5: Error: Can't use 'id' because it is declared more than once.
    id,
    ^
lib/marine/orm/models/voyage.g.dart:319:13: Error: Can't use 'id' because it is declared more than once.
      {this.id,
            ^^
lib/marine/orm/models/voyage.g.dart:322:12: Error: Can't use 'id' because it is declared more than once.
      this.id,
           ^^
lib/marine/orm/models/voyage.g.dart:405:24: Error: Can't use 'id' because it is declared more than once.
        id: id ?? this.id,
                       ^^
lib/marine/orm/models/voyage.g.dart:405:24: Error: The getter 'id' isn't defined for the class 'Voyage'.
 - 'Voyage' is from 'package:aggregation_server/marine/orm/models/voyage.dart' ('lib/marine/orm/models/voyage.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'id'.
        id: id ?? this.id,
                       ^^
lib/marine/orm/models/voyage.g.dart:408:24: Error: Can't use 'id' because it is declared more than once.
        id: id ?? this.id,
                       ^^
lib/marine/orm/models/voyage.g.dart:408:24: Error: The getter 'id' isn't defined for the class 'Voyage'.
 - 'Voyage' is from 'package:aggregation_server/marine/orm/models/voyage.dart' ('lib/marine/orm/models/voyage.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'id'.
        id: id ?? this.id,
                       ^^
lib/marine/orm/models/voyage.g.dart:408:9: Error: Duplicated named argument 'id'.
        id: id ?? this.id,
        ^^
lib/marine/orm/models/voyage.g.dart:430:21: Error: Can't use 'id' because it is declared more than once.
        other.id == id &&
                    ^
lib/marine/orm/models/voyage.g.dart:433:21: Error: Can't use 'id' because it is declared more than once.
        other.id == id &&
                    ^
lib/marine/orm/models/voyage.g.dart:454:7: Error: Can't use 'id' because it is declared more than once.
      id,
      ^
lib/marine/orm/models/voyage.g.dart:451:7: Error: Can't use 'id' because it is declared more than once.
      id,
      ^
lib/marine/orm/models/voyage.g.dart:472:24: Error: Can't use 'id' because it is declared more than once.
    return 'Voyage(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, id=$id, vesselId=$vesselId, departurePortScheduledId=$departurePortScheduledId, departurePortActualId=$departurePortActualId, departureTimeScheduled=$departureTimeScheduled, departureTimeActual=$departureTimeActual, arrivalPortScheduledId=$arrivalPortScheduledId, arrivalPortActualId=$arrivalPortActualId, arrivalTimeScheduled=$arrivalTimeScheduled, arrivalTimeActual=$arrivalTimeActual, latestLatitude=$latestLatitude, latestLongitude=$latestLongitude, status=$status)';
                       ^
lib/marine/orm/models/voyage.g.dart:472:76: Error: Can't use 'id' because it is declared more than once.
    return 'Voyage(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, id=$id, vesselId=$vesselId, departurePortScheduledId=$departurePortScheduledId, departurePortActualId=$departurePortActualId, departureTimeScheduled=$departureTimeScheduled, departureTimeActual=$departureTimeActual, arrivalPortScheduledId=$arrivalPortScheduledId, arrivalPortActualId=$arrivalPortActualId, arrivalTimeScheduled=$arrivalTimeScheduled, arrivalTimeActual=$arrivalTimeActual, latestLatitude=$latestLatitude, latestLongitude=$latestLongitude, status=$status)';
                                                                           ^
lib/marine/orm/models/voyage.g.dart:525:9: Error: Duplicated named argument 'id'.
        id: map['id'] as String?,
        ^^
Error: AOT compilation failed
Generating AOT kernel dill failed!

@kevinelliott
Copy link
Contributor Author

@dukefirehawk Any thoughts?

@kevinelliott
Copy link
Contributor Author

OK, so turns out it was just because I was extending Model. If I remove that, it all seemingly works (thus no collision there). Hopefully I'm not missing out on anything else by not extending!

@dukefirehawk
Copy link
Collaborator

We are currently looking into updating ORM to support models defined in multiple files. Will look into this issue together.

@alguintu
Copy link

alguintu commented Dec 27, 2023

@dukefirehawk

We are currently looking into updating ORM to support models defined in multiple files. Will look into this issue together.

Any update to this feature? Found out this was the missing info to why my attempts to create relationships was failing. Models NEEDED to be in a single file. This info should be prominent in the documentation. I was wondering how the examples were working importing private classes like:

@hasMany
List<_Book> get books;

@belongsTo
_Author get author;

Took me way too long to figure this out. For now I started using part of to maintain the models in separate files, bridging them together with a generic models.dart and models.g.dart as a workaround. Hopefully this feature gets rolled out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants