Here is my current model with the issue:
class Virtual < ActiveRecord::Base
belongs_to :team
named_scope :compiled_this_week, lambda { { :conditions =>
[‘created_at > ? and created_at < ?’, Time.now.beginning_of_week,
Time.now.end_of_week] } }
def self.pullstats(model, teamone)
model.find(:all, :conditions => [‘team_id = ?’, teamone], :order =>
:team_id)
end
def self.start(teamone, teamtwo)
nameone = Team.find(teamone)
nametwo = Team.find(teamtwo)
rushone = compiled_this_week.pullstats(RushingOffense, teamone)
rushtwo = compiled_this_week.pullstats(RushingOffense, teamtwo)
passone = compiled_this_week.pullstats(PassingOffense, teamone)
passtwo = compiled_this_week.pullstats(PassingOffense, teamtwo)
return nameone, nametwo, rushone, rushtwo, passone, passtwo
end
end
My current test uses:
a,b,c,d,e,f = Virtual.start(10,12)
10 and 12 are IDs for different teams.
a = team model for team 10
b = team model for team 12
c = rush model for team 10
d = rush model for team 12
e = rush model for team 10
f = pass model for team 12
The test will pass and data can be pulled and I can view the data using
var.fieldname etc. to show the data comparisons between both teams.
However, I know this has got to be a very long way of doing things.
Normally I would try to use a :joins statement and plop each table side
by side to one another and then just pull the respective fields. Only,
I don’t think I can do that with my current model.
Virtual Model has (no data) and the controller is just being used for
grabbing data. I have a total of 37 tables and I’m just not certain how
to pull the data without doing something as clunky as what I’m doing.
From what I understand, I can only do a :joins from a model that
belongs_to another model… i.e. RushingOffense belongs_to :team so I can
do RushingOffense.find(:all, :joins => [:team]) but I can’t do
Team.find(:all, :joins => [:rushing_offense]). If I try the latter I’ll
get an error about not finding an association.
I setup my data so that all my data tables belong_to team and team has
many data tables. I just want to do a side by side comparison of two
teams. What is the best way to accomplish this?
Should I move away from the virtual controller and go back to the teams
controller and create a specific view and reference everything from
there? Or, should I continue with the clunky way I’m doing it now…?