aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorTeddy Wing2018-01-30 14:48:01 +0100
committerTeddy Wing2018-01-30 14:51:26 +0100
commit82ecc871b8b9409b09fc89f41ff9d65640e6f8ca (patch)
treea3cc7fdfd970f3c9d1dec5547320e15942870f43 /app/models
parent617a54cf63d7f11111b168534d49cdc04a5865d4 (diff)
downloadchouette-core-82ecc871b8b9409b09fc89f41ff9d65640e6f8ca.tar.bz2
VehicleJourney: Allow deletion of associated company
If the state doesn't contain a company, that means it was deleted on the frontend. In that case, the backend code should correctly delete the associated company from the vehicle journey. Refs #5574
Diffstat (limited to 'app/models')
-rw-r--r--app/models/chouette/vehicle_journey.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 8a704d8c0..5cd87a66a 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -221,9 +221,13 @@ module Chouette
def self.state_permited_attributes item
attrs = item.slice('published_journey_identifier', 'published_journey_name', 'journey_pattern_id', 'company_id').to_hash
- ['company', 'journey_pattern'].map do |association|
- attrs["#{association}_id"] = item[association]['id'] if item[association]
+
+ if item['journey_pattern']
+ attrs['journey_pattern_id'] = item['journey_pattern']['id']
end
+
+ attrs['company_id'] = item['company'] ? item['company']['id'] : nil
+
attrs["custom_field_values"] = Hash[*(item["custom_fields"] || {}).map{|k, v| [k, v["value"]]}.flatten]
attrs
end