feathersjs-ecosystem / feathers-objection

Feathers database adapter for Objection.js, an ORM based on KnexJS SQL query builder for Postgres, Redshift, MSSQL, MySQL, MariaDB, SQLite3, and Oracle. Forked from feathers-knex.
MIT License
98 stars 48 forks source link

$modifyEager issue #122

Closed vasilevich closed 4 years ago

vasilevich commented 4 years ago

Hey, I am using $eager to load a table and sub tables as objects in one-to-many relation

I tried using $modifyEager to filter the rows based on the sub-objects. however it seems to just apply to the sub-object making it null and not letting me filter the row itself out of the results?

how would I go about doing that?

eg:

service.customer.find(   query: {
        $eager: 'ticketDetails', $modifyEager: {ticketDetails: {id: 1}},
});

I expect it to return all the customers that have a ticketDetails with an id = 1 .

but it returns all customers, and those who don't have ticketDetails.id=1 have ticketDetails = null

how would I go about achieving what I want?

Thanks

vasilevich commented 4 years ago

well I managed to solve that:

service.customer.find(   
 query: {
        $joinRelation: 'ticketDetails',
        $eager: 'ticketDetails',
        $not: {
          "ticketDetails.id": 2,
        },

      }
);