Skip to content

Commit 4904834

Browse files
AJ ChristensenEl Draper
authored andcommitted
Fixed the archive searcher to use repository.adapter.query instead of self.find_by_sql as the behaviour has changed. Also fixed the specific_date_function to no longer load up the config/database.yml
1 parent 3ecb1bc commit 4904834

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

app/models/article.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def find_by_permalink(permalink)
131131
end
132132

133133
def get_archive_hash
134-
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")
134+
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")
135135
archives = counts.map do |entry|
136136
{
137137
:name => "#{Date::MONTHNAMES[entry.month.to_i]} #{entry.year}",
@@ -145,8 +145,7 @@ def get_archive_hash
145145

146146
private
147147
def specific_date_function
148-
# 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!
149-
if YAML::load(File.read("config/database.yml"))[Merb.environment.to_sym][:adapter] == 'sqlite3'
148+
if Merb::Orms::DataMapper.full_config[Merb.environment.to_s]["adapter"] == "sqlite3"
150149
"strftime('%Y', published_at) as year, strftime('%m', published_at) as month"
151150
else
152151
"extract(year from published_at) as year, extract(month from published_at) as month"

0 commit comments

Comments
 (0)