Skip to content

Commit

Permalink
Reference relations and vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
senhalil committed May 4, 2021
1 parent 0e3507d commit 7566d86
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions models/concerns/expand_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def add_relation_references
relation.linked_services.each{ |service|
service.relations << relation
}
relation.linked_vehicles.each{ |vehicle|
vehicle.relations << relation
}
}
end

Expand Down
1 change: 1 addition & 0 deletions models/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Relation < Base
field :linked_ids, default: []
has_many :linked_services, class_name: 'Models::Service'
field :linked_vehicle_ids, default: []
has_many :linked_vehicles, class_name: 'Models::Vehicle'
field :periodicity, default: 1

# ActiveHash doesn't validate the validator of the associated objects
Expand Down
1 change: 1 addition & 0 deletions models/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Vehicle < Base
has_many :capacities, class_name: 'Models::Capacity'
# include ValidateTimewindows # <- This doesn't work
has_many :rests, class_name: 'Models::Rest'
has_many :relations, class_name: 'Models::Relation'

def self.create(hash)
if hash[:sequence_timewindows]&.size&.positive? && hash[:unavailable_days]&.size&.positive? # X&.size&.positive? is not the same as !X&.empty?
Expand Down

0 comments on commit 7566d86

Please sign in to comment.