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

Querying with joins #44

Closed
boardfish opened this issue Jan 8, 2021 · 1 comment
Closed

Querying with joins #44

boardfish opened this issue Jan 8, 2021 · 1 comment

Comments

@boardfish
Copy link

I'd like for something like this to work: Document.joins(:user).where(users: { admin: true }).

This is probably quite difficult to achieve, since it's converted back to an SQL query by Arel under the hood. It's also worth noting that Arel isn't a stable interface, so it'll probably have some maintenance overhead. Not surprised if this doesn't get addressed, but is there a recommended way to phrase queries like this?

@boardfish
Copy link
Author

Settled on this:

Document.joins(:user).where(User.bitfield_sql(admin: true))

Makes sense for Bitfields to be responsible for its SQL output, so I'll stick with this. Hope it helps anyone that's trying to achieve the same thing.

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