diff --git a/models/index.js b/models/index.js index 15c2718..39ca631 100644 --- a/models/index.js +++ b/models/index.js @@ -82,6 +82,8 @@ db.activeRegion.belongsToMany( } ); +db.SelectedCounties.belongsTo(db.chapter, {foreignKey:'chapter_code', targetKey:'code'}); + db.sequelize.sync(options); // TODO: This is a temporary kludge. These shouldn't really be part diff --git a/models/selectedCounties.js b/models/selectedCounties.js index 6582073..ac42a49 100644 --- a/models/selectedCounties.js +++ b/models/selectedCounties.js @@ -18,7 +18,10 @@ module.exports = function(sequelize, DataTypes) { return sequelize.define('SelectedCounties', { - region: DataTypes.TEXT, + chapter_code: { + field: 'chapter', + type: DataTypes.TEXT + }, state: DataTypes.TEXT, county: DataTypes.TEXT }) diff --git a/views/index.js b/views/index.js index 6bfeb67..f87267f 100644 --- a/views/index.js +++ b/views/index.js @@ -23,7 +23,7 @@ exports.saveRequest = function(req, res) { return utils.findCountyFromAddress(address, zip_for_lookup); }).then( function(county_id){ if (county_id){ - region_code = county_id.region; + region_code = county_id.chapter.region; } else { region_code = 'XXXX'; diff --git a/views/sms/index.js b/views/sms/index.js index 76caf3d..8f7ce45 100644 --- a/views/sms/index.js +++ b/views/sms/index.js @@ -209,7 +209,7 @@ exports.respond = function(req, res) { return save_utils.findCountyFromAddress(address, zip); }).then( function(county_id){ if (county_id){ - region_code = county_id.region; + region_code = county_id.chapter.region; } else { region_code = 'XXXX'; diff --git a/views/utilities.js b/views/utilities.js index 75c73a5..e86b410 100644 --- a/views/utilities.js +++ b/views/utilities.js @@ -375,6 +375,7 @@ module.exports = { requestData.stateFromZip = address['state']; return db.SelectedCounties.findOne({ + include: [ db.chapter ], where: { // Use the PostgreSQL "ILIKE" (case-insensitive LIKE) // operator so that internal inconsistencies in the