views:

15

answers:

1

Hi Guys

I just asked a question about this.. But i now have another question i can't figure out :( So i have a many_to_many relationship pages has many groups and groups has many pages.
Page.all( :include => :groups,
          :conditions => ["#{Group.table_name}.id IS NULL AND client_id='#{session[:client_id]}' AND parent_id IS NULL"])

For some reason this doesn't work. Does anybody know why ?
Removing the #{group.table}.id is NULL works..

I don't get it.

A: 

Ok figured is out.. Stupid mistake .. But how often do you write your own SQL? .. NEVER :P here it is: Page.all(:include => :groups, :conditions => ["#{Group.table_name}.id IS NULL AND #{Page.table_name}.client_id='#{session[:client_id]}' AND #{Page.table_name}.parent_id IS NULL"])

WHen using an include apparently you need to specify the table name. :P

Please no sql-injection code anymore, fix it from `'#{session[:client_id]}'` to `:conditions => ['#{Page.table_name}.client_id = ?', session[:client_id]]`
Dmitry Polushkin