spec/shared/relations.rb in rom-repository-1.3.1 vs spec/shared/relations.rb in rom-repository-1.3.2
- old
+ new
@@ -7,22 +7,28 @@
before do
configuration.relation(:books) do
schema(:books) do
attribute :id, ROM::SQL::Types::Serial
+ attribute :author_id, ROM::SQL::Types.ForeignKey(:users)
attribute :title, ROM::SQL::Types::String
attribute :created_at, ROM::SQL::Types::Time
attribute :updated_at, ROM::SQL::Types::Time
+
+ associations do
+ belongs_to :users, as: :author, relation: :authors, foreign_key: :author_id
+ end
end
end
configuration.relation(:users) do
schema(infer: true) do
associations do
has_many :posts
has_many :posts, as: :aliased_posts
has_many :labels, through: :posts
+ has_many :books, foreign_key: :author_id
end
end
def by_name(name)
where(name: name)
@@ -33,9 +39,13 @@
end
def find(criteria)
where(criteria)
end
+ end
+
+ configuration.relation(:authors) do
+ schema(:users, infer: true)
end
configuration.relation(:tasks) do
schema(infer: true) do
associations do