Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Objection JS get extra properties from joined table + filter

I have the following Model:

class Profile extends Model {

.......................

  static relationMappings = {
    finishers: {
      relation: Model.ManyToManyRelation,
      modelClass: Move,
      filter: (query) => query.select('move.id', 'move.type'),
      join: {
        from: 'profile.id',
        through: {
          from: 'profile_move.profile_id',
          to: 'profile_move.move_id',
          extra: {
            alternative_name: 'name',
          },
        },
        to: 'move.id',
      },
    },
  };
}

What I'm trying to do is to get only move.id & move.type from the move table and also the extra property name from the profile_move joined table. The problem is that if I use filter or a modifier it returns only move.id & move.type and not the extra property.

Route:

router.get('/', async (req, res, next) => {
  try {
    const data = await Profile.query()
      .orderBy('id')
      .withGraphFetched('finishers');

    res.json(data);
  } catch (error) {
    next(error);
  }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The solution is to pass the extra property to filter:

filter: (query) => query.select('move.id', 'move.type', 'profile_move.name'),
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!