Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the options object when fetching related data #2119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

daviddutch
Copy link

Introduction

The options object is passed a bit everywhere and isn't passed to relations. By passing the options object into relations, this opens countless possibilities, such as filtering data according to logged-in user rights directly into the relation.

Motivation

Our main use case is filtering related data according to the user rights. To be able to do this, we need to access a context object to know who is the logged-in user. Currently, relations can't be "dynamic" and adapt to a tenant or other contextual data.

Proposed solution

By simply passing the options object to the related fetching, we can implement something like this:

topics: function (options) {
    return this
        .hasMany('Topic')
        .query(qb => {
            qb
                .whereExists(MeetingDbQueries.filterByTopicsAccess(options.context.user.id));
        });
}

Current PR Issues

I didn't encounter any issues up to now.

Alternatives considered

I've tried many ways to access some data from the relation function unsuccessfully.

Thank you for considering this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant