Vincit / objection.js

An SQL-friendly ORM for Node.js

Home Page:https://vincit.github.io/objection.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`withGraphFetched` doesn't result `runAfter` modification

KcZLog opened this issue · comments

Using withGraphFetch with child modifier, which has runAfter doesn't return modified child object from runAfter.
Using same modifier directly in child model works as expected.

Reproduce using reproduction-template.js:

await Person.query().insertGraph({
  firstName: 'Jennifer',
  lastName: 'Lawrence',

  pets: [
    {
      name: 'Doggo',
      species: 'dog',
    },
  ],
});

const modifiers = {
  onlyNames(builder) {
    // return values only
    builder.select('name').runAfter(
      (pets) => pets.map((p) => p.name)
    );
  },
};

const jennifer = await Person.query()
  .findOne({ firstName: 'Jennifer' })
  .modifiers(modifiers)
  .withGraphFetched('pets(onlyNames)');

const petNames = await Animal.query()
  .modifiers(modifiers)
  .modify('onlyNames');

const expectPets = ['Doggo'];

chai.expect(petNames).to.have.members(expectPets); // success

chai.expect(jennifer.pets).to.have.members(expectPets); // fails