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

Adding orHas and orHasNot query functions #753

Open
rickgoemans opened this issue Sep 10, 2021 · 0 comments
Open

Adding orHas and orHasNot query functions #753

rickgoemans opened this issue Sep 10, 2021 · 0 comments

Comments

@rickgoemans
Copy link

Is your feature request related to a problem? Please describe...

In our project we have a use case of needed a orHasNot.
Our goal is to retrieve all work orders which are not planned (planned_start is null) OR don't have a users assigned to it so that we can show in a planning tool which work orders require an action (planning and/or assigning a user.

Describe the solution you'd like

WorkOrder
    .query()
    .with(...) // Left out for demo purposes
    .where((workOrder, query) => {
        query.where('planned_start', null)
            .orHasNot('users')
    })
    .orderBy(...) // Left out for demo purposes
    .get()

Describe alternatives you've considered

The alternative that we are forced to use now is (my opinion) ugly code and can be seen below:

WorkOrder
    .query()
    .with(...) // Left out for demo purposes
    .where((workOrder, query) => {
        if (!workOrder.planned_start) {
            query.where('planned_start', null)
        } else {
            query.hasNot('users')
        }
    })
    .orderBy(...) // Left out for demo purposes
    .get()

Additional context

I'm looking for something like ->orHas(...) and/or ->orDoesntHave(...) in Laravel. Though considering Vuex's naming with relations I expect them to be called .orHas(...) and .orHasNot('...').

It would also be highly appreciated if these function can accept a callback as 2nd argument just like has does to further determine which relationships should match.

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

No branches or pull requests

1 participant