Created
March 20, 2013 03:36
-
-
Save losvedir/5202121 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
| class CreateOrganizations < ActiveRecord::Migration | |
| def change | |
| create_table :organizations do |t| | |
| t.string :name | |
| t.boolean :has_octocats | |
| t.timestamps | |
| end | |
| 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 CreateTeams < ActiveRecord::Migration | |
| def change | |
| create_table :teams do |t| | |
| t.string :name | |
| t.references :organization | |
| t.timestamps | |
| end | |
| 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 Organization < ActiveRecord::Base | |
| has_many :teams | |
| attr_accessible :name, :has_octocats | |
| scope :has_octocats_scope, lambda { where(:has_octocats => true) } | |
| def self.has_octocats_class_method | |
| where(:has_octocats => true) | |
| 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 Team < ActiveRecord::Base | |
| belongs_to :organization | |
| attr_accessible :name | |
| def self.using_octocats_scope | |
| where(:organization_id => Organization.has_octocats_scope.select(:id)) | |
| end | |
| def self.using_octocats_class_method | |
| where(:organization_id => Organization.has_octocats_class_method.select(:id)) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment