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

Already on GitHub? Sign in to your account

Allow nested conditions passed to .where to build arel tables in some cases #9859

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

DanOlson commented Mar 21, 2013

When passing a hash of conditions to .where, instantiate an arel table
if the keys represent a table associated to engine's table. Maintain
existing behavior if the keys are attributes of engine's table.
This allows queries like these:

  Post.joins(:author => :organization).
    where(:authors => { :organizations => { :name => 'Acme' } } )

Previously, that same query's WHERE clause would read:

"... WHERE "authors"."organizations" ...

which would break because the 'authors' table doesn't have an 'organizations' column. This change will instantiate an Arel::Table for 'organizations', and the query will be built correctly

@DanOlson DanOlson Allow nested conditions to build arel tables
When passing a hash of conditions to .where, instantiate an arel table
if the keys represent a table associated to engine's table. Maintain
existing behavior if the keys are attributes of engine's table.
This allows queries like these:

  Post.joins(:author => :organization).
    where(:authors => { :organizations => { :name => 'Acme' } } )
e9ad41b
Member

senny commented Apr 5, 2013

@DanOlson Is there a reason that this PR points to 3-2-stable? Is this only a problem on 3.2.x or also on master?

As this changes the behavior I don't think it should be backported to 3-2-stable.

Member

jonleighton commented Apr 5, 2013

The current behaviour exists for security reasons, to prevent unsafe query generation. So we can't merge this.

@jonleighton jonleighton closed this Apr 5, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment