Permalink
Browse files

Changed complex queries to use get by sql and fixed badgesto be assoc…

…iated with events not users
  • Loading branch information...
1 parent 7943045 commit 4bebe573eea7902bc0da5c79e7136a80912e7751 @valderrama valderrama committed Nov 5, 2011
@@ -16,14 +16,18 @@ def show
@group = Group.find(params[:id])
@group_name = @group.visible_name
@group_users = @group.users
- #change to find_by_sql more efficient
- @group_future_events = @group.events.where("\"events\".\"start_date\" > \"#{DateTime.now}\"")
- .limit(4).order("start_date DESC").find(:all)
- @group_past_events = @group.events.where("\"events\".\"start_date\" < \"#{DateTime.now}\"")
- .limit(2).order("start_date DESC").find(:all)
- #@group_upcoming_events = @group.events.find_by_start_date(:limit => 4, :order => "start_date DESC")
- #@group_past_events = @group.events.where("start_date > #{Time.now}").limit(1).order("start_date DESC")
- #@group_blog_posts =
+ @group_future_events = Event.find_by_sql(["SELECT *
+ FROM groups g, events_groups eg, events e, events_locations el, locations l
+ WHERE g.id = ? AND g.id = eg.group_id AND e.id = eg.event_id
+ AND e.start_date > ? AND e.id = el.event_id AND l.id = el.location_id
+ ORDER BY e.start_date DESC
+ LIMIT 4", params[:id], DateTime.now])
+ @group_past_events = Event.find_by_sql(["SELECT *
+ FROM groups g, events_groups eg, events e, events_locations el, locations l
+ WHERE g.id = ? AND g.id = eg.group_id AND e.id = eg.event_id
+ AND e.start_date < ? AND e.id = el.event_id AND l.id = el.location_id
+ ORDER BY e.start_date DESC
+ LIMIT 2", params[:id], DateTime.now])
respond_to do |format|
format.html # show.html.erb
@@ -0,0 +1,5 @@
+class DropBadgesUsersTable < ActiveRecord::Migration
+ def change
+ drop_table :badges_users
+ end
+end
@@ -0,0 +1,8 @@
+class AssociateBadgesWithEvents < ActiveRecord::Migration
+ def change
+ create_table :badges_events, :id => false do |t|
+ t.integer :badge_id
+ t.integer :user_id
+ end
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111008214655) do
+ActiveRecord::Schema.define(:version => 20111105010323) do
create_table "badges", :force => true do |t|
t.string "name"
@@ -20,7 +20,7 @@
t.datetime "updated_at"
end
- create_table "badges_users", :id => false, :force => true do |t|
+ create_table "badges_events", :id => false, :force => true do |t|
t.integer "badge_id"
t.integer "user_id"
end
Oops, something went wrong.

0 comments on commit 4bebe57

Please sign in to comment.