Skip to content

Commit

Permalink
Fixed the archive searcher to use repository.adapter.query instead of…
Browse files Browse the repository at this point in the history
… self.find_by_sql as the behaviour has changed. Also fixed the specific_date_function to no longer load up the config/database.yml
  • Loading branch information
AJ Christensen authored and El Draper committed Jul 18, 2008
1 parent 3ecb1bc commit 4904834
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/models/article.rb
Expand Up @@ -131,7 +131,7 @@ def find_by_permalink(permalink)
end

def get_archive_hash
counts = self.find_by_sql("SELECT COUNT(*) as count, #{specific_date_function} FROM articles WHERE published_at IS NOT NULL AND published = 1 GROUP BY year, month ORDER BY year DESC, month DESC")
counts = repository.adapter.query("SELECT COUNT(*) as count, #{specific_date_function} FROM articles WHERE published_at IS NOT NULL AND published = 1 GROUP BY year, month ORDER BY year DESC, month DESC")
archives = counts.map do |entry|
{
:name => "#{Date::MONTHNAMES[entry.month.to_i]} #{entry.year}",
Expand All @@ -145,8 +145,7 @@ def get_archive_hash

private
def specific_date_function
# This is pretty nasty loading up the db.yml to get at this, but I wasn't able to find the method in merb just yet. Change it!
if YAML::load(File.read("config/database.yml"))[Merb.environment.to_sym][:adapter] == 'sqlite3'
if Merb::Orms::DataMapper.full_config[Merb.environment.to_s]["adapter"] == "sqlite3"
"strftime('%Y', published_at) as year, strftime('%m', published_at) as month"
else
"extract(year from published_at) as year, extract(month from published_at) as month"
Expand Down

0 comments on commit 4904834

Please sign in to comment.