How can I pass something to set_table_name so that I can switch tables
on the fly for accessing archive data?
If I could access sessions inside a model I would do something like:
if @session[:current_period]
set_table_name “statistics_” + @session[:archive_year]
else
set_table_name “statistics_” + Date.now.year
end
But since I cannot access the session from within a model how do I tell
the model to archive data which is held in a different table eg.
“statistics_2005” ?
How can I pass something to set_table_name so that I can switch tables
on the fly for accessing archive data?
If I could access sessions inside a model I would do something like:
if @session[:current_period]
set_table_name “statistics_” + @session[:archive_year]
else
set_table_name “statistics_” + Date.now.year
end
But since I cannot access the session from within a model how do I tell
the model to archive data which is held in a different table eg.
“statistics_2005” ?
Many thanks, K.
Unless this is a legacy DB, I suggest changing it so you don’t have to
have lots of statistics tables.
Otherwise(untested): #in your model
def find_correct_table(sess)
if sess[:current_period]
set_table_name “statistics_#{sess[:archive_year]}”
else
set_table_name “statistics_#{Date.now.year}”
end
The in your controller:
Model.find_correct_table(session)
Its not a legacy table, but because there is so much data it needs to be
archived in to a seperate table for logical and performance reasons.
From your example it looks like you can use session’s in the model?
Many thanks.
joey__ wrote:
Kris wrote:
How can I pass something to set_table_name so that I can switch tables
on the fly for accessing archive data?
If I could access sessions inside a model I would do something like:
if @session[:current_period]
set_table_name “statistics_” + @session[:archive_year]
else
set_table_name “statistics_” + Date.now.year
end
But since I cannot access the session from within a model how do I tell
the model to archive data which is held in a different table eg.
“statistics_2005” ?
Many thanks, K.
Unless this is a legacy DB, I suggest changing it so you don’t have to
have lots of statistics tables.
Otherwise(untested): #in your model
def find_correct_table(sess)
if sess[:current_period]
set_table_name “statistics_#{sess[:archive_year]}”
else
set_table_name “statistics_#{Date.now.year}”
end
The in your controller:
Model.find_correct_table(session)