开发者

:include rails mutliple sql statement RAILS

I ju开发者_开发知识库st 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜