Created
June 28, 2012 16:25
-
-
Save keppy/3012287 to your computer and use it in GitHub Desktop.
Modeling a debate app
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
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