hhtokpinar / sqfEntity

SqfEntity ORM for Flutter/Dart lets you build and execute SQL commands on SQLite database easily and quickly with the help of fluent methods similar to .Net Entity Framework. SqfEntity also generates add/edit forms with validations and special controls (DropDown List, DateTime pickers, Checkboxes.. etc) for your table.
379 stars 101 forks source link

Apparent infinite loop with many to many relationship and preload: true #283

Open JWambaugh opened 2 years ago

JWambaugh commented 2 years ago

If I query a table with a many-to-many relationship and use .toList(preload: true), the query never returns if retrieving a record with related records. It looks like it gets stuck in an infinite loop.

A simplified version of my model for example:

const tableImage = SqfEntityTable(
    tableName: 'image',
    primaryKeyName: 'id',
    primaryKeyType: PrimaryKeyType.integer_auto_incremental,
    useSoftDeleting: false,
    modelName: null,
    fields: [
      SqfEntityField('fileName', DbType.text),
    ]);

const tableAlbums = SqfEntityTable(
    tableName: 'album',
    primaryKeyName: 'id',
    primaryKeyType: PrimaryKeyType.integer_auto_incremental,
    useSoftDeleting: false,
    modelName: null,
    fields: [
      SqfEntityField('name', DbType.text),

      SqfEntityFieldRelationship(
        parentTable: tableImage,
        relationType: RelationType.MANY_TO_MANY,
        manyToManyTableName: "albumImage",
        deleteRule: DeleteRule.CASCADE,
      )
    ])

then for example if I run:

return await Image().select().toList(preload: true); // <- never returns