Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

sql variable substitution on :joins

#992

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 users_for_admin_check.id = posts.user_id'.
    :conditions => ['users_for_admin_check.admin = ?', true] }
end

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 users_for_admin_check.id = posts.user_id and users_for_admin_checking.admin = ?', true]
  }
end

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

Reported by Mathijs Kwik · September 8th, 2008 @ 12:28 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Pratik
    Pratik
    • State changed from new to invalid

    I think you should just use :conditions.

    December 20th, 2008 @ 03:28 PM