Skip to content

Instance method $relatedQuery returns undefined #1606

@destructor465

Description

@destructor465

So basically I have 3 models: Event, User and Ticket.
Ticket connects Event and User as it has eventId and userId.
And so this is a way I use relations to collect all in the event participating users:

users: {
	relation: Model.HasOneThroughRelation,
	modelClass: 'user',
	join: {
		from: 'events.id',
		through: {
			from: 'tickets.eventId',
			to: 'tickets.userId'
		},
		to: 'users.id'
	}
}

in relationMappings() static method.

And there's where I encountered something strange. If there's no tickets for specific event and so no users, static Event.relatedQuery<User>('users').for(event.id); works fine - returns empty list. However if I use event instance event.$relatedQuery<User>('users'); it returns undefined.
In docs it's said that instance method is just a shortcut for static method, but both returns different results in this case.

Node - 12.13.1
Objection - 2.0.5
knex - 0.20.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions