sqfEntity icon indicating copy to clipboard operation
sqfEntity copied to clipboard

Many to many generation error

Open Joyker opened this issue 4 years ago • 13 comments

Hello, thank you for this library. I found that many to many table is not generated. After build_runner i see that this table exist in model.g file, but not added to databaseTables list.

To generate right database i had to modify Model.g file manually, adding this table to models databaseTables list. But, after i got right sqlite file i can`t use preload:true, it just freezes and stops without error.

versions:
sqfentity: ^1.4.0 sqfentity_gen: ^1.4.0

Joyker avatar Aug 19 '20 19:08 Joyker

In the sample, there’s a model called chinook and it has a many-to-many relation. Can you check it to make sure you if there’s any difference with your model?

hhtokpinar avatar Aug 19 '20 20:08 hhtokpinar

Thank you for quick response. Yes, i checked it. My sample model more simple, but it has the same many to many relationship (of course with changed parentTable).

I looked through closed issues, version 1.4.0-dev.1.4 does not help :(

Joyker avatar Aug 19 '20 21:08 Joyker

I'm facing the exact same issue. I can't use preload nor loadParents. The many to many table is generated but not initialized because its not present in the databaseTables in MyModelDB class. If I add the Table.getInstance manually it works, but still no preload nor loadParents work. Also everytime I generate the model it remover from the databaseTables, so I have to add it again for it to work.

rodrigomoretto avatar Nov 12 '20 13:11 rodrigomoretto

I'm facing the exact same issue. I can't use preload nor loadParents. The many to many table is generated but not initialized because its not present in the databaseTables in MyModelDB class. If I add the Table.getInstance manually it works, but still no preload nor loadParents work. Also everytime I generate the model it remover from the databaseTables, so I have to add it again for it to work.

Can you prep a dummy simple model that has a many-to-many relationship and try it again? If it won’t work so I can connect your computer to check what’s wrong. email me at [email protected]

hhtokpinar avatar Nov 13 '20 10:11 hhtokpinar

Hi every one,

Have you found a solution for this issue? Because I get the same behavior.

I work with the bellow version: sqfentity: ^1.4.0+3 sqfentity_gen: ^1.4.0

Thanks in advance for your help, and thanks for this good library.

Daniel

dan-gandolfo avatar Jan 07 '21 10:01 dan-gandolfo

@hhtokpinar I've made a repository with the occurring error here:

https://github.com/rodrigomoretto/Many2ManySqfEntityFlutter

Hope it helps.

Also @dangabdolfo have you tried using sqfentity_gen: ^1.4.0+2 ?

rodrigomoretto avatar Jan 08 '21 20:01 rodrigomoretto

@hhtokpinar I've made a repository with the occurring error here:

https://github.com/rodrigomoretto/Many2ManySqfEntityFlutter

Hope it helps.

Also @dangabdolfo have you tried using sqfentity_gen: ^1.4.0+2 ?

Thanks for sharing. I'm looking now.

hhtokpinar avatar Jan 09 '21 13:01 hhtokpinar

Hi, I suppose I removed many2many related fields in the collection list because of causing a StackOverflow error look at this line (at 3766, sqfentity_gen/lib/sqfentity_base.dart file) (https://github.com/hhtokpinar/sqfEntity/blob/master/sqfentity_gen/lib/sqfentity_base.dart#L3766)

List<TableCollectionBase> _getCollections(
    SqfEntityTableBase table, SqfEntityModelBase _m) {
  final collectionList = <TableCollectionBase>[];
  for (var _table in _m.databaseTables
      .where((t) => t.relationType != RelationType.MANY_TO_MANY)) {
    for (var field
        in _table.fields.whereType<SqfEntityFieldRelationshipBase>()) {
      if (field.table == null && _table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(table, field,
            relationType: field.relationType));
      } else if (field.table != null &&
          field.table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(_table, field,
            relationType: field.relationType));
      }
    }
  }
  return collectionList;
}

you can test it after remowing that where clause ( .where((t) => t.relationType != RelationType.MANY_TO_MANY) in the full package I think it will generate preloading methods but will not work

hhtokpinar avatar Jan 09 '21 18:01 hhtokpinar

Hi, sorry I might have mistaken that with another test I was trying.

Here is the repository I made, I thought updated remotely but was just on my local.

Anyways, the problem in here that I mentioned in readme is just using the generation. I will make a runtime test when I get a bit more time soon. But basically it says that after you generate the tables that have a many to many relationship that table is generated, however its not instantiated to the databaseTables from the BaseModel (My database name). Instantiating it works, hoever everytime I make another generation it gets deleted, requiring me to make the process of adding it again.

Also preload and loadparents doesn't seem to work.

Anyway hope that this helps.

Edit1: I was just typing and correcting my example when you said that

Hi, I suppose I removed many2many related fields in the collection list because of causing a StackOverflow error look at this line (at 3766, sqfentity_gen/lib/sqfentity_base.dart file) (https://github.com/hhtokpinar/sqfEntity/blob/master/sqfentity_gen/lib/sqfentity_base.dart#L3766)

List<TableCollectionBase> _getCollections(
    SqfEntityTableBase table, SqfEntityModelBase _m) {
  final collectionList = <TableCollectionBase>[];
  for (var _table in _m.databaseTables
      .where((t) => t.relationType != RelationType.MANY_TO_MANY)) {
    for (var field
        in _table.fields.whereType<SqfEntityFieldRelationshipBase>()) {
      if (field.table == null && _table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(table, field,
            relationType: field.relationType));
      } else if (field.table != null &&
          field.table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(_table, field,
            relationType: field.relationType));
      }
    }
  }
  return collectionList;
}

you can test it after remowing that where clause ( .where((t) => t.relationType != RelationType.MANY_TO_MANY) in the full package I think it will generate preloading methods but will not work

rodrigomoretto avatar Jan 09 '21 18:01 rodrigomoretto

Hi, sorry for the delay. I have tried with the version 1.4.0+2 of the sqfentity_gen and I get the same result.

All code about the many2many tables is generated but the tables are not created in the database. If I add manually the "getInstance" for the many2many tables one the provider, all tables are created correctly but like for you, the preload does not work.

Thanks for tour answer.

dan-gandolfo avatar Jan 11 '21 13:01 dan-gandolfo

anyone tried that I explained?

Hi, I suppose I removed many2many related fields in the collection list because of causing a StackOverflow error look at this line (at 3766, sqfentity_gen/lib/sqfentity_base.dart file) (https://github.com/hhtokpinar/sqfEntity/blob/master/sqfentity_gen/lib/sqfentity_base.dart#L3766)

List<TableCollectionBase> _getCollections(
    SqfEntityTableBase table, SqfEntityModelBase _m) {
  final collectionList = <TableCollectionBase>[];
  for (var _table in _m.databaseTables
      .where((t) => t.relationType != RelationType.MANY_TO_MANY)) {
    for (var field
        in _table.fields.whereType<SqfEntityFieldRelationshipBase>()) {
      if (field.table == null && _table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(table, field,
            relationType: field.relationType));
      } else if (field.table != null &&
          field.table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(_table, field,
            relationType: field.relationType));
      }
    }
  }
  return collectionList;
}

you can test it after remowing that where clause ( .where((t) => t.relationType != RelationType.MANY_TO_MANY) in the full package I think it will generate preloading methods but will not work

hhtokpinar avatar Jan 11 '21 15:01 hhtokpinar

anyone tried that I explained?

Hi, I suppose I removed many2many related fields in the collection list because of causing a StackOverflow error look at this line (at 3766, sqfentity_gen/lib/sqfentity_base.dart file) (https://github.com/hhtokpinar/sqfEntity/blob/master/sqfentity_gen/lib/sqfentity_base.dart#L3766)

List<TableCollectionBase> _getCollections(
    SqfEntityTableBase table, SqfEntityModelBase _m) {
  final collectionList = <TableCollectionBase>[];
  for (var _table in _m.databaseTables
      .where((t) => t.relationType != RelationType.MANY_TO_MANY)) {
    for (var field
        in _table.fields.whereType<SqfEntityFieldRelationshipBase>()) {
      if (field.table == null && _table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(table, field,
            relationType: field.relationType));
      } else if (field.table != null &&
          field.table.tableName == table.tableName) {
        collectionList.add(TableCollectionBase(_table, field,
            relationType: field.relationType));
      }
    }
  }
  return collectionList;
}

you can test it after remowing that where clause ( .where((t) => t.relationType != RelationType.MANY_TO_MANY) in the full package I think it will generate preloading methods but will not work

I'm trying it right now. I have to make changes in my for because I couldn't make it work locally.

rodrigomoretto avatar Jan 11 '21 15:01 rodrigomoretto

I can't download my package, pub get won't allow. Here is what I'm doing:

On my pubspec.yaml, is like this:

dependencies:
  sqfentity: ^1.4.0+3

dev_dependencies:
  sqfentity_gen:
    git:
      url: https://github.com/rodrigomoretto/sqfEntity.git
      path: sqfentity_gen
      ref: d89d271
  build_runner: ^1.10.1
  build_verify: ^1.1.1
  sqflite_common_ffi: ^1.1.0+1

but it gives me the following error:

[MyApp] flutter pub get
Running "flutter pub get" in MyApp...                     
Because sqfentity 1.4.0+3 depends on sqfentity_gen >=1.4.0 <3.0.0 and no versions of sqfentity match >1.4.0+3 <2.0.0, sqfentity ^1.4.0+3 requires sqfentity_gen from hosted.
So, because app depends on both sqfentity ^1.4.0+3 and sqfentity_gen from git, version solving failed.

pub get failed (1; So, because app depends on both sqfentity ^1.4.0+3 and sqfentity_gen from git, version solving failed.)
exit code 1

But if I try to move sqfentity to devdependencies and point to my repository like this:

dev_dependencies:
  sqfentity:
    git:
      url: https://github.com/rodrigomoretto/sqfEntity.git
      path: sqfentity
      ref: d89d271
  sqfentity_gen:
    git:
      url: https://github.com/rodrigomoretto/sqfEntity.git
      path: sqfentity_gen
      ref: d89d271
  build_runner: ^1.10.1
  build_verify: ^1.1.1
  sqflite_common_ffi: ^1.1.0+1

Thats the error that follows:

[MyApp] flutter pub get
Running "flutter pub get" in MyApp...                     
Because app depends on sqfentity from git which depends on sqfentity_gen >=1.4.0 <3.0.0, sqfentity_gen from hosted is required.
So, because app depends on sqfentity_gen from git, version solving failed.

pub get failed (1; So, because erp depends on sqfentity_gen from git, version solving failed.)
exit code 1

Sorry if I'm making any mistake on how to set this up, and please let me know how to do it. I've never done something like this.

Anyway, here is the link to the repo:

https://github.com/rodrigomoretto/sqfEntity

And thanks in advance for the help.

rodrigomoretto avatar Jan 11 '21 16:01 rodrigomoretto