Hi Julian,
Thank you for your reply…i have been using up a very big part of my
time trying to better understand all of the eager loading issues, it is
obviously important, and so i’ll take as much time as i need to fully
understand it - - thanks for helping me along the way.
as i have a has_and_belongs_to_many relashinship between groups and
users (and groups_users, accordingly), the issue at hand is this:
i need to select an array of users including all of the groups
associated with them, determined by (the condition part of the story)
- a query string entered in a searchbar
- groups that were chosen
( i have a searchbar that you can choose one or many groups to look
under, and under the users in those groups, perform a search query
[…like…%%…])
so…as i’ve been trying to do this for a while, i tried implementing
the search for users while only looking according to the groups
chosen(without the search string query) and it worked fine (like a
charm!) but when i tried adding an AND users.title like ? , #{query}
statment to the conditions it failed on me.
…this is according to what you’ve shown me(and it works great):
groups = @groups.join(’,’)
@users = User.find(:all, :conditions => “group_id IN (#{groups})”,
:include => :groups")
…this is what i’ve added(and it fails):
@users = User.find(:all, :conditions => [“group_id IN (#{groups} AND
USERS.TITLE LIKE ?”, #{PARAMS[:QUERY]}], :include => :groups)
it outputs this error:
“SELECT * FROM as t0_r0…LEFT OUTER JOIN users on…LEFT OUTER JOIN
groups ON groups.id = groups_users.group_id WHERE (group_id IN (10) AND
users.title like %something%)”
…stating the problem was on the where clause. it must be a stupid
mistake or something, but i’ve been spending so much time on it already,
it’s a task of survival of sanity here…so how do i change the “…and
users.title” to go into the users on LEFT OUTER JOIN where clause? i
even tried to play around with a through clause (admitably, i don’t know
how to use, but tried at the least) but it errored a “unknown key
through”…
it doesn’t seem that rails wouldn’t have a very simple solution, but it
obviously was thrown way over my head.
i am in great debt,
thanks again,
harp