Created
June 27, 2011 00:37
-
-
Save brycemcd/1048132 to your computer and use it in GitHub Desktop.
Ruby Relationships without the database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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