Hi all,
I''m trying to construct a find() without resorting to find_by_sql() -
I''m stuck. It seems simple enough, I have 2 simple models:
class Game < ActiveRecord::Base
belongs_to :home_team, :class_name => ''Team'',
:foreign_key =>
''home_team_id''
belongs_to :away_team, :class_name => ''Team'',
:foreign_key =>
''away_team_id''
belongs_to :league
end
class Team < ActiveRecord::Base
has_many :home_games, :class_name => "Game", :foreign_key
=>
"home_team_id"
has_many :away_games, :class_name => "Game", :foreign_key
=>
"away_team_id"
end
Now I want to return all games from a text search where the search
phrase matches (with like %phrase%) the home team name or the away
team name. I''ve been trying variation of this to no avail:
@games = Game.find(:all,
:includes => [ :home_team, :away_team ],
:conditions => [ ''lower(game.home_team.name) like ? or lower
(game.away_team.name) like ? '', ''%'' +
@phrase.downcase + ''%'' ],
:order => ''date desc'',
:limit => 5)
Any suggestions? I''m pulling my hair out and I figure their has to
be way besides writing out the SQL query...
Thanks!