jaguar_orm
jaguar_orm copied to clipboard
analyzer version too low for compatibility with null-safe packages
Everything is in the title
@SebastienSCochet I did a null-safe migration of the LegacyV3 branch, not sure if that helps
https://github.com/JamesMcIntosh/jaguar_orm/tree/legacyV3
It's not too far of what's actually in master, doesn't seem like much has changed since the V3 branch
https://github.com/Jaguar-dart/jaguar_orm/compare/legacyV3
Hi,
I tried to use your verson @SebastienSCochet, but I got a lot of problems with the generator, and I did my own implementation of null safety based on the next versions:
Flutter: 1.22.6
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
jaguar_orm: ^2.2.7
jaguar_query_sqflite: ^2.2.9
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^1.2.2
jaguar_orm_gen: ^2.2.30
analyzer: ^0.38.0
build_resolvers: ^1.2.0
json_serializable: ^3.0.0
If you know how to publish in the flutter package repository pub.dev or if you have some documentation to follow, please share it.
If you want to use my implementation in your flutter projects, just change the references as this:
Flutter: 2.2.3
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
jaguar_orm:
git:
url: https://github.com/isaacfi/jaguar_orm_nullsafe.git
path: orm
jaguar_query_sqflite:
git:
url: https://github.com/isaacfi/jaguar_orm_nullsafe.git
path: sqflite
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.0
jaguar_orm_gen:
git:
url: https://github.com/isaacfi/jaguar_orm_nullsafe.git
path: generator
analyzer: ^1.5.0
build_resolvers: ^2.0.4
json_serializable: ^4.1.4
dependency_overrides:
meta: ^1.3.0
@isaacfi That's a shame you had to do all the same work again when we could have improved the existing pull request... It would be helpful to get some feedback on what wasn't working for you on the PR #198
@JamesMcIntosh Is not the same work, you have too many issues, and I insist that are in generator, your implementation finished the build process with errors. Did you test the generator? with relationships? That's why I did my own and I deleted extra files that doesn't nothing. I don't care if you don't want to consider it.
BR
Hi @isaacfi, By "same" I mean we both did work to get the code null-safe. I have tested but not with relationships, thanks for letting me know. I'll see if the example projects have some good test cases. It's always good to consider other peoples input, ideas and help, I will review what you've done and see what can be brought into the PR for the legacyV3 branch. Thanks!
@tejainece do you have any time to help get that PR merged back in?
@isaacfi Why creating a new repo instead of forking this one? Your work doesn't work completely too : for example, one-to-many relation doesn't work. I started from your repo ( https://github.com/isaacfi/jaguar_orm_nullsafe ) and created a pull request with some modifications (one-to-many and others) : https://github.com/Jaguar-dart/jaguar_orm/pull/199
@JamesMcIntosh Sorry I created another PR, but was not able to make your code work... It looked simpler to start from @isaacfi work...
@tejainece It would be awesome if you have some time to look and merge the pull requests or to do the null safe migration yourself
Hi @dedeweb,
I have one-to-many relationships in my project, the only that I need was change the creation of the related Beans. For example: I have a table named JobCategory that has one to many relationship with the table Job (One job category has many jobs). And this is the code of my model:
For Job Category:
import 'package:jaguar_orm/jaguar_orm.dart';
import 'package:json_annotation/json_annotation.dart';
import 'job_model.dart';
part 'job_category_model.g.dart';
part 'job_category_model.jorm.dart';
@JsonSerializable()
class JobCategoryModel {
@PrimaryKey()
late int jobCategoryId;
@Column(length: 50, isNullable: false)
late String name;
@Column(length: 150, isNullable: false)
late String description;
@IgnoreColumn()
String? image;
@Column(isNullable: false)
late bool isEnabled;
@HasMany(JobModelBean)
List<JobModel>? jobs;
JobCategoryModel();
@override
String toString() {
return toJson().toString();
}
factory JobCategoryModel.fromJson(Map<String, dynamic> json) =>
_$JobCategoryModelFromJson(json);
Map<String, dynamic> toJson() => _$JobCategoryModelToJson(this);
}
@GenBean()
class JobCategoryModelBean extends Bean<JobCategoryModel>
with _JobCategoryModelBean {
JobCategoryModelBean(Adapter adapter) : super(adapter);
JobModelBean? _jobModelBean;
@override
JobModelBean get jobModelBean => _jobModelBean ??= JobModelBean(adapter);
@override
String get tableName => 'JobCategory';
}
And for Job:
import 'package:jaguar_orm/jaguar_orm.dart';
import 'package:json_annotation/json_annotation.dart';
import 'job_category_model.dart';
part 'job_model.g.dart';
part 'job_model.jorm.dart';
@JsonSerializable()
class JobModel {
@PrimaryKey()
late int jobId;
@BelongsTo(JobCategoryModelBean,
refCol: 'jobCategoryId', isNullable: false, byHasMany: true)
late int jobCategoryId;
@Column(length: 50, isNullable: false)
late String name;
@Column(length: 150, isNullable: false)
late String description;
@IgnoreColumn()
String? image;
@Column(isNullable: false)
late bool isVisitForBudgetRecommended;
@Column(isNullable: false)
late bool isEnabled;
JobModel();
@override
String toString() {
return toJson().toString();
}
factory JobModel.fromJson(Map<String, dynamic> json) =>
_$JobModelFromJson(json);
Map<String, dynamic> toJson() => _$JobModelToJson(this);
}
@GenBean()
class JobModelBean extends Bean<JobModel> with _JobModelBean {
JobModelBean(Adapter adapter) : super(adapter);
JobCategoryModelBean? _jobCategoryModelBean;
@override
JobCategoryModelBean get jobCategoryModelBean =>
_jobCategoryModelBean ??= JobCategoryModelBean(adapter);
@override
String get tableName => 'Job';
}
As you can see the relationship beans, are created as getter properties and this avoid the problem of the creation of the main beans when you run the generation.
I created a new repo, because the legacyV3 doesnt work to me, because in this version is not posible to have a Foreign-Primary Key and I have some tables that got it. Then what I did is use the code downloaded by pub get of the version of jaguar-orm and change the code to make compatible with null-safe.
And I'll review you pull request, but try to generate your model as mine, I'm sure that will work at all.
BR.
Sorry, but it didn't work for me, I always had a "mismatching association type"' exception
In parser.dart line 97, you compare byHasMany with other.hasMany, but byHasMany is affected with foreign.byHasMany which should be nullable and is not.