Skip to content

Instantly share code, notes, and snippets.

@nuclearsandwich
Created March 19, 2013 20:28
Show Gist options
  • Save nuclearsandwich/5199808 to your computer and use it in GitHub Desktop.
Save nuclearsandwich/5199808 to your computer and use it in GitHub Desktop.
class Identity < ActiveRecord::Base
belongs_to :user
has_many :accounts
# relation logic methods.
end
class Account < ActiveRecord::Base
belongs_to :identity
end
class TwitterAccount < Account
end
class FacebookAccount < Account
end
class YoutubeAccount < Account
end
class User < ActiveRecord::Base
has_one :identity
def aggregate_social_nonsense
identity.aggregate_social_nonsense
end
end
class BetterNameThanStageRelationForDescribingRelationshipBetweenIntakeAndStage < ActiveRecord::Base
belongs_to :intake
has_one :stage
has_many :demos
has_many :loans
has_many :releases
def each_by_date
# To the best of my knowledge there's no Ruby that can interleave these as they come from the database.
(demos.order_by(:date) + loans.order_by(:date) + releases.order_by(:date)).sort_by(&:date)
end
end
class Intake < ActiveRecord::Base
has_one :BetterNameThanStageRelationForDescribingRelationshipBetweenIntakeAndStages.underscored
end
class Demo < ActiveRecord::Base
belongs_to :BetterNameThanStageRelationForDescribingRelationshipBetweenIntakeAndStages.underscored
end
class Loan < ActiveRecord::Base
belongs_to :BetterNameThanStageRelationForDescribingRelationshipBetweenIntakeAndStages.underscored
end
class Release < ActiveRecord::Base
belongs_to :BetterNameThanStageRelationForDescribingRelationshipBetweenIntakeAndStages.underscored
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment