Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@losvedir
Created March 20, 2013 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save losvedir/5202121 to your computer and use it in GitHub Desktop.
Save losvedir/5202121 to your computer and use it in GitHub Desktop.
class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.string :name
t.boolean :has_octocats
t.timestamps
end
end
end
class CreateTeams < ActiveRecord::Migration
def change
create_table :teams do |t|
t.string :name
t.references :organization
t.timestamps
end
end
end
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
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