Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relations and vehicles reference each other #146

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -104,6 +104,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