Skip to content

Instantly share code, notes, and snippets.

@goodviber
Last active May 9, 2017 16:52
Show Gist options
  • Save goodviber/caa097d445d291d555c44d146757b31b to your computer and use it in GitHub Desktop.
Save goodviber/caa097d445d291d555c44d146757b31b to your computer and use it in GitHub Desktop.
survey modelling
# app/models/particiapnt.rb
class Participant < ActiveRecord::Base
belongs_to :country
has_many :answers
has_many :questions, through: :answers
end
# app/models/survey.rb
class Survey < ActiveRecord::Base
has_many :questions
has_many :response_periods
has_many :countries, through: :response_periods
accepts_nested_attributes_for :questions
end
# app/models/question.rb
class Question < ActiveRecord::Base
belongs_to :goals
belongs_to :survey
has_many :answers
has_many :participants, through: :answers
accepts_nested_attributes_for :answers
end
#app/models/theme.rb
class Theme < ActiveRecord::Base
has_many :goals
has_many :resources, through: :goals
accepts_nested_atributes_for :goals
end
#app/models/goal.rb
class Goal < ActiveRecord::Base
belongs_to :theme
has_many :questions
has_many :resources
accepts_nested_attributes_for :resources
end
#app/models/region.rb
class Region < ActiveRecord::Base
belongs_to :user
has_many :countries
end
#app/models/country.rb
class Country < ActiveRecord::Base
belongs_to :region
has_many :surveys
has_many :response_periods
accepts_nested_attributes_for :response_period
end
#app/models/response_period.rb
class ResponsePeriod < ActiveRecord::Base
belongs_to :country
belongs_to :survey
end
#app/models/resource.rb
belongs_to :goal
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment