Skip to content

Commit 3cb603f

Browse files
committed
Small tidy ups to local authority models
This makes a couple of minor changes to the local authority related models to tidy up the code.
1 parent 7df5a31 commit 3cb603f

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

app/models/local_authority.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
# index_local_authorities_on_nation_and_short_name (nation,short_name)
2626
# index_local_authorities_on_short_name (short_name)
2727
#
28+
2829
class LocalAuthority < ApplicationRecord
2930
self.primary_key = :mhclg_code
3031

3132
validates :mhclg_code, uniqueness: true
3233
validates :gias_code, uniqueness: true, allow_nil: true
3334
validates :gss_code, uniqueness: true, allow_nil: true
3435

35-
has_many :postcodes,
36-
foreign_key: :gss_code,
37-
primary_key: :gss_code,
38-
class_name: "LocalAuthority::Postcode"
36+
has_many :postcodes, foreign_key: :gss_code, primary_key: :gss_code
3937

4038
enum :nation,
4139
{
@@ -80,8 +78,6 @@ def self.from_my_society_import_row(data)
8078
end
8179

8280
def self.for_postcode(postcode)
83-
joins(:postcodes).merge(
84-
LocalAuthority::Postcode.where(value: postcode)
85-
).first
81+
joins(:postcodes).merge(Postcode.where(value: postcode)).first
8682
end
8783
end

app/models/local_authority/postcode.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
# index_local_authority_postcodes_on_gss_code (gss_code)
1515
# index_local_authority_postcodes_on_value (value) UNIQUE
1616
#
17+
1718
class LocalAuthority::Postcode < ApplicationRecord
18-
belongs_to :local_authority,
19-
foreign_key: :gss_code,
20-
primary_key: :gss_code,
21-
optional: true
19+
belongs_to :local_authority, foreign_key: :gss_code, primary_key: :gss_code
2220

2321
normalizes :value,
2422
with: ->(given_value) do

app/models/location.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# index_locations_on_urn (urn) UNIQUE WHERE ((type = 0) AND (site IS NULL))
3232
# index_locations_on_urn_and_site (urn,site) UNIQUE
3333
#
34+
3435
class Location < ApplicationRecord
3536
self.inheritance_column = nil
3637

0 commit comments

Comments
 (0)