Add trips
This commit is contained in:
18
lib/adamantium/persistence/relations/post_trips.rb
Normal file
18
lib/adamantium/persistence/relations/post_trips.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Adamantium
|
||||
module Persistence
|
||||
module Relations
|
||||
class PostTrips < ROM::Relation[:sql]
|
||||
schema :post_trips, infer: true do
|
||||
associations do
|
||||
belongs_to :post
|
||||
belongs_to :trip
|
||||
end
|
||||
end
|
||||
|
||||
auto_struct(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -8,6 +8,9 @@ module Adamantium
|
||||
associations do
|
||||
has_many :post_tags
|
||||
has_many :tags, through: :post_tags
|
||||
|
||||
has_many :post_trips
|
||||
has_many :trips, through: :post_trips
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +19,11 @@ module Adamantium
|
||||
def published
|
||||
where(self[:published_at] <= Time.now)
|
||||
end
|
||||
|
||||
def published_between(start_date, end_date)
|
||||
where(self[:published_at] >= start_date)
|
||||
.where(self[:published_at] <= end_date)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
18
lib/adamantium/persistence/relations/trips.rb
Normal file
18
lib/adamantium/persistence/relations/trips.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Adamantium
|
||||
module Persistence
|
||||
module Relations
|
||||
class Trips < ROM::Relation[:sql]
|
||||
schema :trips, infer: true do
|
||||
associations do
|
||||
has_many :post_trips
|
||||
has_many :posts, through: :post_trips
|
||||
end
|
||||
end
|
||||
|
||||
auto_struct(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user