Skip to content

Instantly share code, notes, and snippets.

@brycemcd
Created June 27, 2011 00:37
Show Gist options
  • Select an option

  • Save brycemcd/1048132 to your computer and use it in GitHub Desktop.

Select an option

Save brycemcd/1048132 to your computer and use it in GitHub Desktop.
Ruby Relationships without the database
class Ballroom
# returns an array of all the ballroom titles
def self.all_titles
tables.collect { |x| x[0] }
end
# returns an array of table ids.
def self.get(table)
tables[table]
end
private
# this is a listing of all the ballrooms by name. This is quite manual but since this data never changes, we're okay
def self.districts
#works like this:
# "ballroom title" => [table1.id, table2.id ... tablen.id]
{
"The Grand Room" => (1..20).map,
"Crystal Ballroom" => [21, 22],
"Emerald Ballroom" => [23, 24, 25]
}
end
end
class Chairs << ActiveRecord::Base
named_scope :chairs_in_ballroom, lambda { |table_ids|
{ :conditions => ["table_id IN (?)", table_ids] }
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment