Election results in the London Borough of Sutton.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 lines
2.5 KiB

  1. require 'dm-core'
  2. require 'dm-validations'
  3. require 'dm-timestamps'
  4. class Postcode
  5. include DataMapper::Resource
  6. property :id, Serial
  7. property :postcode, String, :required => true
  8. property :created_at, DateTime, :required => true
  9. property :lat, Float, :required => true
  10. property :lng, Float, :required => true
  11. property :district_name, String, :required => true
  12. property :district_code, String, :required => true
  13. property :ward_name, String, :required => true
  14. property :ward_code, String, :required => true
  15. end
  16. class Ward
  17. include DataMapper::Resource
  18. property :id, Serial
  19. property :ons_id, String, :required => true
  20. property :name, String, :required => true
  21. property :constituency_id, Integer, :required => true
  22. has n, :councilcandidates, :order => [ 'surname' ]
  23. belongs_to :constituency
  24. def self.slugify(name)
  25. name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  26. end
  27. end
  28. class Party
  29. include DataMapper::Resource
  30. property :id, Serial
  31. property :name, String, :required => true
  32. has n, :councilcandidates, :order => [ 'surname' ]
  33. has n, :parliamentcandidates, :order => [ 'surname' ]
  34. end
  35. class Councilcandidate
  36. include DataMapper::Resource
  37. property :id, Serial
  38. property :ward_id, Integer, :required => true
  39. property :party_id, Integer, :required => true
  40. property :forenames, String, :required => true
  41. property :surname, String, :required => true
  42. property :address, String, :length => 200
  43. property :postcode, String, :required => true
  44. belongs_to :party
  45. belongs_to :ward
  46. end
  47. class Parliamentcandidate
  48. include DataMapper::Resource
  49. property :id, Serial
  50. property :constituency_id, Integer, :required => true
  51. property :party_id, Integer, :required => true
  52. property :forenames, String, :required => true
  53. property :surname, String, :required => true
  54. property :address, String, :length => 200
  55. property :postcode, String
  56. belongs_to :party
  57. belongs_to :constituency
  58. end
  59. class Constituency
  60. include DataMapper::Resource
  61. property :id, Serial
  62. property :name, String, :required => true
  63. has n, :wards, :order => 'name'
  64. has n, :parliamentcandidates, :order => [ 'surname' ]
  65. end
  66. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  67. DataMapper.auto_upgrade!