This project is archived and is in readonly mode.

#992 ✓invalid
Mathijs Kwik

sql variable substitution on :joins

Reported by Mathijs Kwik | September 8th, 2008 @ 12:28 AM | in 2.x

I would like to have substitution+sanitizing features on :joins.

class Post
  belongs_to :user
  named_scope :by_admins, {
    :joins => 'inner join users as users_for_admin_check on = posts.user_id'.
    :conditions => ['users_for_admin_check.admin = ?', true] }

Here I had to move the condition to :conditions, just to get the ? substitution. I need the substitution in this case because boolean values are handled differently on sqlite/mysql.

In this case I would have liked to keep it all in the join, since this is actually a join condition.

class Post
  belongs_to :user
  named_scope :by_admins, {
    :joins => ['inner join users as users_for_admin_check on = posts.user_id and users_for_admin_checking.admin = ?', true]

I think it doesn't interfere with other stuff, since with the current behavior, it acts the same as when using symbols in an array.

at the moment: Using :joins => :symbol will try some inner join for association named :symbol Using :joins => 'string' will just put the string in the sql query. Using :joins => [:symbol, :symbol] will include inner joins for all associations Using :joins => ['string', *values] will try the same as with symbols above, which is inconsistent considering the difference between symbols and strings without the array.

Any chance this can get implemented? Thanks

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket