Skip to content

Include/IncludeList does not take current transaction into account #2802

Closed

Description

@hampuslavin

Describe the bug
The following test case should pass but it currently fails:

test(
    'Given finding an object and including related object'
    'when organization has people then includeList should include people',
    () async {
  await session.db.transaction((transaction) async {
    var serverpod = await Organization.db.insertRow(
      session,
      Organization(name: 'Serverpod'),
      transaction: transaction,
    );

    var person1 = await Person.db.insertRow(
      session,
      Person(name: 'John Doe'),
      transaction: transaction,
    );
    var person2 = await Person.db.insertRow(
      session,
      Person(name: 'Jane Doe'),
      transaction: transaction,
    );

    await Organization.db.attach.people(
      session,
      serverpod,
      [person1, person2],
      transaction: transaction,
    );

    var organizations = await Organization.db.find(
      session,
      orderBy: (t) => t.id,
      include: Organization.include(
        people: Person.includeList(),
      ),
      transaction: transaction,
    );

    expect(organizations[0].people, hasLength(2)); // <-- FAILS! 
  });
});

Fails with:

Expected: an object with length of <2>
  Actual: []
   Which: has length of <0>

The issue appears to be that the following database method does not take transaction into account:

Future<Map<String, Map<int, List<Map<String, dynamic>>>>> _queryIncludedLists(
Session session,
Table table,
Include? include,
Iterable<Map<String, dynamic>> previousResultSet,
) async {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions