diff options
| author | mo khan <mo@mokhan.ca> | 2014-02-22 13:03:45 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-02-22 13:03:45 -0700 |
| commit | d363dc6298e8210fb3a5eddea8a6916a54005290 (patch) | |
| tree | d722fbe64f53cfa4f05312e7444f007bb30c15f2 | |
| parent | d62b19c584862b3c54559348475a93fffd985e7f (diff) | |
switch from has_one to belongs_to relationship.
| -rw-r--r-- | app/models/license.rb | 2 | ||||
| -rw-r--r-- | app/models/location.rb | 2 | ||||
| -rwxr-xr-x | bin/sample.rb | 3 | ||||
| -rw-r--r-- | db/migrate/20140222194718_add_location_id_to_licenses.rb | 6 | ||||
| -rw-r--r-- | db/schema.rb | 4 |
5 files changed, 12 insertions, 5 deletions
diff --git a/app/models/license.rb b/app/models/license.rb index 12bb387..b7e1dff 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,7 +1,7 @@ class License < ActiveRecord::Base belongs_to :company belongs_to :well_type - has_one :location + belongs_to :location belongs_to :applicant, class_name: 'User', foreign_key: 'user_id' def status diff --git a/app/models/location.rb b/app/models/location.rb index b74eabc..5587398 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,3 +1,3 @@ class Location < ActiveRecord::Base - belongs_to :license, autosave: true + has_one :license, autosave: true end diff --git a/bin/sample.rb b/bin/sample.rb index e1e92a3..97bfcf0 100755 --- a/bin/sample.rb +++ b/bin/sample.rb @@ -9,12 +9,13 @@ hal = User.create(first_name: 'hal', last_name: 'kvisle', company: xyz_resources township_1 = Location.create(latitude: 51.06, longitude: -114.09, township: '1') township_2 = Location.create(latitude: 40.06, longitude: -100.09, township: '2') +township_3 = Location.create(latitude: 30.06, longitude: -90.01, township: '3') public_license = jd.apply_for_license(WellType::NFW, township_1) public_license.update_attribute(:issued_at, 1.day.ago) public_license.update_attribute(:expired_at, 1.year.from_now) -public_expired_license = jd.apply_for_license(WellType::DPT, township_1) +public_expired_license = jd.apply_for_license(WellType::DPT, township_3) public_expired_license.update_attribute(:issued_at, 1.year.ago) public_expired_license.update_attribute(:expired_at, 1.day.ago) diff --git a/db/migrate/20140222194718_add_location_id_to_licenses.rb b/db/migrate/20140222194718_add_location_id_to_licenses.rb new file mode 100644 index 0000000..067e7e4 --- /dev/null +++ b/db/migrate/20140222194718_add_location_id_to_licenses.rb @@ -0,0 +1,6 @@ +class AddLocationIdToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :location_id, :uuid + remove_column :locations, :license_id + end +end diff --git a/db/schema.rb b/db/schema.rb index f102db8..b397f77 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222145409) do +ActiveRecord::Schema.define(version: 20140222194718) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,10 +32,10 @@ ActiveRecord::Schema.define(version: 20140222145409) do t.boolean "confidential", default: false t.integer "well_type_id" t.uuid "user_id" + t.uuid "location_id" end create_table "locations", id: :uuid, default: "uuid_generate_v4()", force: true do |t| - t.uuid "license_id" t.float "latitude" t.float "longitude" t.string "township" |
