Initial commit
This commit is contained in:
18
lib/adamantium/persistence/relations/post_tags.rb
Normal file
18
lib/adamantium/persistence/relations/post_tags.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Adamantium
|
||||
module Persistence
|
||||
module Relations
|
||||
class PostTags < ROM::Relation[:sql]
|
||||
schema :post_tags, infer: true do
|
||||
associations do
|
||||
belongs_to :post
|
||||
belongs_to :tag
|
||||
end
|
||||
end
|
||||
|
||||
auto_struct(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
22
lib/adamantium/persistence/relations/posts.rb
Normal file
22
lib/adamantium/persistence/relations/posts.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Adamantium
|
||||
module Persistence
|
||||
module Relations
|
||||
class Posts < ROM::Relation[:sql]
|
||||
schema :posts, infer: true do
|
||||
associations do
|
||||
has_many :post_tags
|
||||
has_many :tags, through: :post_tags
|
||||
end
|
||||
end
|
||||
|
||||
auto_struct(true)
|
||||
|
||||
def published
|
||||
where(self[:published_at] <= Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
lib/adamantium/persistence/relations/tags.rb
Normal file
18
lib/adamantium/persistence/relations/tags.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Adamantium
|
||||
module Persistence
|
||||
module Relations
|
||||
class Tags < ROM::Relation[:sql]
|
||||
schema :tags, infer: true do
|
||||
associations do
|
||||
belongs_to :post_tag
|
||||
belongs_to :post, through: :post_tag
|
||||
end
|
||||
end
|
||||
|
||||
auto_struct(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user