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

Can't filter by associations property on relation (filtered join) #766

Open
mishuagopian opened this issue Jan 26, 2017 · 0 comments
Open

Comments

@mishuagopian
Copy link

mishuagopian commented Jan 26, 2017

Hi @dresende @dxg , I'm getting some trouble to get the query I want to trigger. My models are simple and are the following:

  const pullrequest = db.define('pullrequest', {
    id             :     { type: 'number', required: true },
    number         :     { type: 'number' },
    created_at     :     { type: 'text' },
    finished_at    :     { type: 'text' },
    state          :     { type: 'text' },
    merged         :     { type: 'boolean' },
    owner_id       :     { type: 'number' },
    owner_name     :     { type: 'text' }
  });
  const review = db.define('review', {
    id              :     { type: 'number', required: true },
    reviewer_id     :     { type: 'number' },
    reviewer_name   :     { type: 'text' },
    picked_up_at    :     { type: 'text' },
    submitted_at    :     { type: 'text' },
    state           :     { type: 'text' }
  });
  review.hasOne('pullrequest', pullrequest, { reverse: 'reviews' });

The thing is I can't simply get pull requests that have no reviews. The query I want to trigger can look like the following:

SELECT *
    FROM pullrequest LEFT OUTER JOIN review
    ON pullrequest.id=review.pullrequest_id
    WHERE review.pullrequest_id IS NULL;

I tried to achieve this by doing the following:models.pullrequest.find({ reviews: [] });
but I only got: SELECT "id", "number", "created_at", "finished_at", "state", "merged", "owner_id", "owner_name", "repository_id" FROM "pullrequest".

This is just one example of something I can't retrieve (or don't know how to do it), but another can be to get those pull requests which have any review which state is some specific text.

That's it and thanks in advance!

@mishuagopian mishuagopian changed the title Can't filter by associations property on relation Can't filter by associations property on relation (filtered join) Jan 26, 2017
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