Created
May 7, 2015 00:44
-
-
Save kenmazaika/49d36bb5fe9868d31e4b to your computer and use it in GitHub Desktop.
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
| Places | |
| ------ | |
| id | |
| Comments | |
| ------ | |
| id | |
| place_id | |
| class: Place | |
| database table: places | |
| has_many :comments -> place_id -> Comment | |
| has_many :white_games | |
| has_many :black_games | |
| def all_games | |
| white_games + black_games | |
| end | |
| id | name | |
| 1 | Pizza | |
| 2 | Nom | |
| 3 | Nom | |
| 4 | nom | |
| class: Comment | |
| database table: comments | |
| belongs_to :place -> :place_id -> places.id -> Place | |
| belongs_to :awesome_place, :foreign_key => :awesome_place_id, :class_name => 'Place' | |
| belongs_to :terrible_place, :foreign_key => :terrible_place_id, :class_name => 'Place' | |
| id | awesome_place_id | terrible_place_id | |
| 10 | 2 | 5 | |
| 11 | 2 | 3 | |
| 12 | 3 | 4 | |
| c = Comment.last | |
| c.awesome_place => look up by awesome_place_id | |
| add_index :comments, [:awesome_place_id, :terrible_place_id] | |
| add_index :comments, :terrible_place_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment