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

Repo.get with query not using query arguments #215

Open
faultyserver opened this issue Sep 22, 2018 · 1 comment
Open

Repo.get with query not using query arguments #215

faultyserver opened this issue Sep 22, 2018 · 1 comment

Comments

@faultyserver
Copy link
Contributor

I've run into this a few times now. Using Repo.get with a query passed to it ignores everything about the query except for the preloads. For example:

Repo.get(Session, session_id, Query.where(valid: "true"))

Generates a query like:

SELECT * FROM acc_sessions WHERE key='...' LIMIT 1

Where the valid = "true" has not been added to the query string.

Reading the docs for Repo.get, it looks like that is intentional, but it seems rather limiting and unintuitive to me. Like in the example above, I'd like to be able to use that query parameter as a way of filtering out results that I'm not interested in, rather than having to use Repo.all(...).first.

@repomaa
Copy link

repomaa commented Dec 7, 2018

this is "by design". It's a bit confusing though. the query in Repo.get is only used for preloads. If you want to use wheres you will need to use Repo.get_by. In your case

Repo.get_by(Session, Query.where(id: session_id, valid: "true"))

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

2 participants