Skip to content

Commit

Permalink
Use schema auto-infer
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed May 23, 2016
1 parent 00c0c11 commit 26c17eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/hanami/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def ==(other)
id == other.id
end

def to_h
@attributes.dup
end
alias_method :to_hash, :to_h

private

attr_reader :attributes
Expand Down
2 changes: 1 addition & 1 deletion test/integration/repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
found = repository.find_with_comments(user.id)

found.must_equal user
found.comments.must_equal [comment]
found.comments.map(&:to_h).must_equal [comment.to_h]
end
end
end
11 changes: 2 additions & 9 deletions test/support/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class Comment

class UserRepository < Hanami::Repository
relation(:users) do
schema do
attribute :id, ROM::SQL::Types::Serial # We can copy these types to Hanami
attribute :name, ROM::SQL::Types::String # We can copy these types to Hanami

schema(infer: true) do
associate do
many :comments
end
Expand Down Expand Up @@ -66,11 +63,7 @@ def find_with_comments(id)

class CommentRepository < Hanami::Repository
relation(:comments) do
schema do
attribute :id, ROM::SQL::Types::Serial # We can copy these types to Hanami
attribute :user_id, ROM::SQL::Types::ForeignKey(:users) # We can copy these types to Hanami
attribute :text, ROM::SQL::Types::String # We can copy these types to Hanami
end
schema(infer: true)

def by_id(id)
where(id: id)
Expand Down

0 comments on commit 26c17eb

Please sign in to comment.