Skip to content

Instantly share code, notes, and snippets.

@keppy
Created June 28, 2012 16:25
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 keppy/3012287 to your computer and use it in GitHub Desktop.
Save keppy/3012287 to your computer and use it in GitHub Desktop.
Modeling a debate app
def User
has_many :propositions, :as => :debateable
has_many :oppositions, :as => :debateable
end
def Proposition
belongs_to :debateable, :polymorphic => :true
has_one :opposition, :as => :debateable
end
def Opposition
belongs_to :debateable, :polymorphic => :true
end
# These active record models need to create a world such that:
# A User has many Propositions and Oppositions. However, an Opposition may only be created by User1 in response to a existing Proposition that has already been created by User2. Each Proposition can have only one Opposition.
# The app is meant to display a Proposition along-side its corresponding Opposition. So basically:
# Users should be able to create as many Propositions as they want.
# Users can only create an Opposition in response to an existing Proposition.
# Each Proposition can have either 0 or 1 Oppositions.
# A Proposition and its corresponding Opposition cannot both be owned by the same user.
# Please advise--I'm not sure if I'm on the right track with the associations I've outlined above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment