What is the schema of the SQL tables?
ROM::SQL.migration do
change do
create_table "schedule_it_schedule_elements" do
primary_key :id
foreign_key :schedule_id, "schedule_it_schedules", null: false
foreign_key :event_id, "schedule_it_events", null: false
column :temporal_expression_id, Integer, null: false
column :temporal_expression_type, String, null: false
column :created_at, :timestamp, null: false
column :updated_at, :timestamp, null: false
index [:schedule_id, :event_id], unique: true
end
end
end
ROM::SQL.migration do
change do
create_table "schedule_it_events" do
primary_key :id
column :name, String, null: false
column :effective_at, DateTime, null: false
column :effective_until, DateTime, null: false
column :created_at, :timestamp, null: false
column :updated_at, :timestamp, null: false
end
end
end
Here are the relations…
module Relations
class ScheduleElements < ROM::Relation[:sql]
gateway :default
schema :schedule_it_schedule_elements, infer: true, as: :schedule_elements do
associations do
belongs_to :schedule
belongs_to :event
end
use :timestamps, attributes: %i[created_at updated_at]
end
def within_effective_range(range)
join(:event)
.where {
( event[:effective_at] <= range.max ) &
( event[:effective_until] >= range.min )
}
end
end
end
module Relations
class Events < ROM::Relation[:sql]
gateway :default
schema :schedule_it_events, infer: true, as: :events do
attribute :effective_at, Types::DateTime, read: Types.Constructor(Time, &:to_datetime)
attribute :effective_until, Types::DateTime, read: Types.Constructor(Time, &:to_datetime)
associations do
has_one :schedule_element
end
use :timestamps, attributes: %i[created_at updated_at]
end
end
end
The error comes from calling #within_effective_range(range)