Mongoid

Challenge

Only editable by group admins

  • Last updated November 10, 2018 at 5:00 PM by hankish
  • Evidence only visible to badge awarders
Solve this learning challenge by posting code snippets.

Instructions

Post code snippets for each of the items described below.
You're going to build a simple Mongoid-powered voter registration system with three rails models:
  • A "voter" model - Defines a person who is a voter. Has all the basic details including age. Also has an "interests" string array which stores a list of their political interests. Belongs to a single political party.
  • A "political_party" model - Has a name, description and anything else relevant.
  • A "party_spokesperson" model which is embedded within the "political_party" document (embedded one to many). Has name, email, phone number, etc.. Also has an "interests" string array which stores a list of their political interests. 
Once you've got the rails model files created, post separate code snippet which some example queries:
  • Starting with an array of political parties how would you query all the voters in those parties between the ages of 18 and 25?
  • Starting with a single voter, how would you query for a list of spokespersons for that voter's party who share one or more interests with the voter?