Rails/AR find where habtm does not include?

How about this: User. Find :all, :conditions => 'roles. Id is?

Or roles. Id! =?', nil, Role:admin.

Id , :include => :roles This works for has_many :through seems like it should be the same for HABTM.

How about this: User. Find :all, :conditions => 'roles. Id is?

Or roles. Id! =?', nil, Role:admin.

Id , :include => :roles This works for has_many :through, seems like it should be the same for HABTM.

I'm pretty sure that just finds users without any roles rather than without the specific role. – Shadwell Jul 15 '09 at 18:40 right, read the question too fast. Thanks and fixed it.

– austinfromboston Jul 15 '09 at 19:19.

Use a sub-query and the NOT IN operator User. Find(:all,:conditions => "id NOT IN (select user_id from roles_users where role_id =? )", Role:admin.Id).

I can do User. All - User. Find(:all, :conditions => 'role_id =?', Role:admin.

Id, :joins => :roles) Which accomplishes what I want in two queries, which is probably fine for this project, but if I can get it to a single query it would be nice.

I have a model Publication and a model Category in my Rails app. Both are connected with a has_and_belongs_to_many association. Now I would like to search publications that match one or more categories.

If more than one category is given they have all assigned to the publication. I want to specify the categories in a multiple select_box. Categories_id_is(1,2) is not working because the categories are connected with OR.

Categories_id_is_all(1,2) the categories are connected with AND, but no result is given back. Any idea's on that? Am I mising the right point in the docs.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions