I suppose I could use:
def self.pullstats(model ,team, field) model.find(:all, :select => field, :conditions => ['team_id = ?', team], :order => :team_id) end
And from the controller declare my instance variables as:
@teamone_rush = Virtual.pullstats(RushingOffense, 10, "ydspg") @teamtwo_rush = Virtual.pullstats(RushingOffense, 12, "ydspg") etc.
But as you can see this would amount to (2 teams x 37 models of data with single column retrievals) or:
74 instance variables in the controller..
My problem is I don't know how to associate the Virtuals controller to the rest of the models I want to pull the data from so that I can :join their respective tables to one large query..
I would rather do:
def self.pullstats(team) Team.find(team, :joins => [:rushing_offense, :passing_offense, :total_offense, :scoring_offense, etc. etc., :conditions => ['team_id = ?', team], :order => :team_id) end
This would do side by side joins where the team_id of each table would line up with the team.id of the Teams table.
How can I do the above? Anyone?