hanami-model 1.1.0.beta3 → 1.1.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/hanami-model.gemspec +4 -3
- data/lib/hanami/model/associations/belongs_to.rb +10 -3
- data/lib/hanami/model/associations/has_many.rb +11 -4
- data/lib/hanami/model/associations/many_to_many.rb +10 -1
- data/lib/hanami/model/plugins/mapping.rb +1 -1
- data/lib/hanami/model/plugins/timestamps.rb +1 -1
- data/lib/hanami/model/sql/entity/schema.rb +1 -1
- data/lib/hanami/model/sql/types.rb +12 -2
- data/lib/hanami/model/types.rb +53 -1
- data/lib/hanami/model/version.rb +1 -1
- metadata +32 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac1d93bb8d958c05f22b8a5f14e0072c0c7df823
|
|
4
|
+
data.tar.gz: 369794a0d62a1e06d55181564bc15693e4b0ab46
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e01d7c581d03cecc7eeee81cef39abd574581e015d677ce623ddf0339a336b98f434995583b6008a9fabd275fe41a764ea4c872309c66b2148ff6aef134a102e
|
|
7
|
+
data.tar.gz: '08df89ae8621493379cd07cd7c5f78d7ac380319b7312d33d8f26d57eaa5065549773ed6bf5cbbb965838235fc93c2d9b41cac96c98124e9fbd74ad1157c6815'
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Hanami::Model
|
|
2
2
|
A persistence layer for Hanami
|
|
3
3
|
|
|
4
|
+
## v1.1.0.rc1 - 2017-10-16
|
|
5
|
+
### Added
|
|
6
|
+
- [Marcello Rocha] Added support for associations aliasing via `:as` option (`has_many :users, through: :comments, as: :authors`)
|
|
7
|
+
- [Luca Guidi] Allow entities to be used as type in entities manual schema (`attribute :owner, Types::Entity(User)`)
|
|
8
|
+
|
|
4
9
|
## v1.1.0.beta3 - 2017-10-04
|
|
5
10
|
|
|
6
11
|
## v1.1.0.beta2 - 2017-10-03
|
|
@@ -21,6 +26,16 @@ A persistence layer for Hanami
|
|
|
21
26
|
### Fixed
|
|
22
27
|
- [Sean Collins] Enhanced error message for Postgres `db create` and `db drop` when `createdb` and `dropdb` aren't in `PATH`
|
|
23
28
|
|
|
29
|
+
## v1.0.4 - 2017-10-14
|
|
30
|
+
### Fixed
|
|
31
|
+
- [Nikita Shilnikov] Keep the dependency on `dry-sql` at `~> 1.3`, which is compatible with `dry-types` `~> 0.11.0`
|
|
32
|
+
- [Nikita Shilnikov] Ensure to write Postgres JSON (`PGJSON`) type for nested associated records
|
|
33
|
+
- [Nikita Shilnikov] Ensure `Repository#select` to work with `Hanami::Model::MappedRelation`
|
|
34
|
+
|
|
35
|
+
## v1.0.3 - 2017-10-11
|
|
36
|
+
### Fixed
|
|
37
|
+
- [Luca Guidi] Keep the dependency on `dry-types` at `~> 0.11.0`
|
|
38
|
+
|
|
24
39
|
## v1.0.2 - 2017-08-04
|
|
25
40
|
### Fixed
|
|
26
41
|
- [Maurizio De Magnis] URI escape for Postgres password
|
data/hanami-model.gemspec
CHANGED
|
@@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.require_paths = ['lib']
|
|
19
19
|
spec.required_ruby_version = '>= 2.3.0'
|
|
20
20
|
|
|
21
|
-
spec.add_runtime_dependency 'hanami-utils', '1.1.0.
|
|
22
|
-
spec.add_runtime_dependency 'rom
|
|
21
|
+
spec.add_runtime_dependency 'hanami-utils', '1.1.0.rc1'
|
|
22
|
+
spec.add_runtime_dependency 'rom', '~> 3.3', '>= 3.3.2'
|
|
23
|
+
spec.add_runtime_dependency 'rom-sql', '~> 1.3', '>= 1.3.5'
|
|
23
24
|
spec.add_runtime_dependency 'rom-repository', '~> 1.4'
|
|
24
|
-
spec.add_runtime_dependency 'dry-types', '~> 0.11'
|
|
25
|
+
spec.add_runtime_dependency 'dry-types', '~> 0.11.0'
|
|
25
26
|
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
|
26
27
|
|
|
27
28
|
spec.add_development_dependency 'bundler'
|
|
@@ -82,15 +82,22 @@ module Hanami
|
|
|
82
82
|
# @since 1.1.0
|
|
83
83
|
# @api private
|
|
84
84
|
def association_keys
|
|
85
|
-
|
|
86
|
-
.associations[target]
|
|
85
|
+
association
|
|
87
86
|
.__send__(:join_key_map, container.relations)
|
|
88
87
|
end
|
|
89
88
|
|
|
89
|
+
# Return the ROM::Associations for the source relation
|
|
90
|
+
#
|
|
91
|
+
# @since 1.1.9
|
|
92
|
+
# @api private
|
|
93
|
+
def association
|
|
94
|
+
relation(source).associations[target]
|
|
95
|
+
end
|
|
96
|
+
|
|
90
97
|
# @since 1.1.0
|
|
91
98
|
# @api private
|
|
92
99
|
def _build_scope
|
|
93
|
-
result = relation(target)
|
|
100
|
+
result = relation(association.target.to_sym)
|
|
94
101
|
result = result.where(foreign_key => subject.fetch(primary_key)) unless subject.nil?
|
|
95
102
|
result.as(Model::MappedRelation.mapper_name)
|
|
96
103
|
end
|
|
@@ -7,7 +7,7 @@ module Hanami
|
|
|
7
7
|
#
|
|
8
8
|
# @since 0.7.0
|
|
9
9
|
# @api private
|
|
10
|
-
class HasMany
|
|
10
|
+
class HasMany # rubocop:disable Metrics/ClassLength
|
|
11
11
|
# @since 0.7.0
|
|
12
12
|
# @api private
|
|
13
13
|
def self.schema_type(entity)
|
|
@@ -177,15 +177,22 @@ module Hanami
|
|
|
177
177
|
# @since 0.7.0
|
|
178
178
|
# @api private
|
|
179
179
|
def association_keys
|
|
180
|
-
|
|
181
|
-
.associations[target]
|
|
180
|
+
target_association
|
|
182
181
|
.__send__(:join_key_map, container.relations)
|
|
183
182
|
end
|
|
184
183
|
|
|
184
|
+
# Returns the targeted association for a given source
|
|
185
|
+
#
|
|
186
|
+
# @since 0.7.0
|
|
187
|
+
# @api private
|
|
188
|
+
def target_association
|
|
189
|
+
relation(source).associations[target]
|
|
190
|
+
end
|
|
191
|
+
|
|
185
192
|
# @since 0.7.0
|
|
186
193
|
# @api private
|
|
187
194
|
def _build_scope
|
|
188
|
-
result = relation(target)
|
|
195
|
+
result = relation(target_association.target.to_sym)
|
|
189
196
|
result = result.where(foreign_key => subject.fetch(primary_key)) unless subject.nil?
|
|
190
197
|
result.as(Model::MappedRelation.mapper_name)
|
|
191
198
|
end
|
|
@@ -158,11 +158,20 @@ module Hanami
|
|
|
158
158
|
association_keys[1].last
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
+
# Return the ROM::Associations for the source relation
|
|
162
|
+
#
|
|
161
163
|
# @since 1.1.0
|
|
162
164
|
# @api private
|
|
165
|
+
def association
|
|
166
|
+
relation(source).associations[target]
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @since 1.1.0
|
|
170
|
+
#
|
|
171
|
+
# @api private
|
|
163
172
|
# rubocop:disable Metrics/AbcSize
|
|
164
173
|
def _build_scope
|
|
165
|
-
result = relation(target).qualified
|
|
174
|
+
result = relation(association.target.to_sym).qualified
|
|
166
175
|
unless subject.nil?
|
|
167
176
|
result = result
|
|
168
177
|
.join(through, target_foreign_key => target_primary_key)
|
|
@@ -122,7 +122,7 @@ module Hanami
|
|
|
122
122
|
# @api private
|
|
123
123
|
def build_associations(registry, associations)
|
|
124
124
|
associations.each_with_object({}) do |(name, association), result|
|
|
125
|
-
target = registry.fetch(
|
|
125
|
+
target = registry.fetch(association.target.to_sym)
|
|
126
126
|
result[name] = Association.lookup(association).schema_type(target)
|
|
127
127
|
end
|
|
128
128
|
end
|
|
@@ -82,11 +82,21 @@ module Hanami
|
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
# @since 1.0.4
|
|
86
|
+
# @api private
|
|
87
|
+
def self.pg_json_pristines
|
|
88
|
+
@pg_json_pristines ||= ::Hash.new do |hash, type|
|
|
89
|
+
hash[type] = if defined?(ROM::SQL::Types::PG)
|
|
90
|
+
ROM::SQL::Types::PG.const_get(type).pristine
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
85
95
|
# @since 1.0.2
|
|
86
96
|
# @api private
|
|
87
97
|
def self.pg_json?(pristine)
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
pristine == pg_json_pristines['JSONB'.freeze] ||
|
|
99
|
+
pristine == pg_json_pristines['JSON'.freeze]
|
|
90
100
|
end
|
|
91
101
|
|
|
92
102
|
private_class_method :pg_json?
|
data/lib/hanami/model/types.rb
CHANGED
|
@@ -17,15 +17,67 @@ module Hanami
|
|
|
17
17
|
# Class level interface
|
|
18
18
|
#
|
|
19
19
|
# @since 0.7.0
|
|
20
|
+
# rubocop:disable Naming/MethodName
|
|
20
21
|
module ClassMethods
|
|
22
|
+
# Define an entity of the given type
|
|
23
|
+
#
|
|
24
|
+
# @param type [Hanami::Entity] an entity
|
|
25
|
+
#
|
|
26
|
+
# @since 1.1.0
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# require "hanami/model"
|
|
30
|
+
#
|
|
31
|
+
# class Account < Hanami::Entity
|
|
32
|
+
# attributes do
|
|
33
|
+
# # ...
|
|
34
|
+
# attribute :owner, Types::Entity(User)
|
|
35
|
+
# end
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# account = Account.new(owner: User.new(name: "Luca"))
|
|
39
|
+
# account.owner.class # => User
|
|
40
|
+
# account.owner.name # => "Luca"
|
|
41
|
+
#
|
|
42
|
+
# account = Account.new(owner: { name: "MG" })
|
|
43
|
+
# account.owner.class # => User
|
|
44
|
+
# account.owner.name # => "MG"
|
|
45
|
+
def Entity(type)
|
|
46
|
+
type = Schema::CoercibleType.new(type) unless type.is_a?(Dry::Types::Definition)
|
|
47
|
+
type
|
|
48
|
+
end
|
|
49
|
+
|
|
21
50
|
# Define an array of given type
|
|
22
51
|
#
|
|
52
|
+
# @param type [Object] an object
|
|
53
|
+
#
|
|
23
54
|
# @since 0.7.0
|
|
24
|
-
|
|
55
|
+
#
|
|
56
|
+
# @example
|
|
57
|
+
# require "hanami/model"
|
|
58
|
+
#
|
|
59
|
+
# class Account < Hanami::Entity
|
|
60
|
+
# attributes do
|
|
61
|
+
# # ...
|
|
62
|
+
# attribute :users, Types::Collection(User)
|
|
63
|
+
# end
|
|
64
|
+
# end
|
|
65
|
+
#
|
|
66
|
+
# account = Account.new(users: [User.new(name: "Luca")])
|
|
67
|
+
# user = account.users.first
|
|
68
|
+
# user.class # => User
|
|
69
|
+
# user.name # => "Luca"
|
|
70
|
+
#
|
|
71
|
+
# account = Account.new(users: [{ name: "MG" }])
|
|
72
|
+
# user = account.users.first
|
|
73
|
+
# user.class # => User
|
|
74
|
+
# user.name # => "MG"
|
|
75
|
+
def Collection(type)
|
|
25
76
|
type = Schema::CoercibleType.new(type) unless type.is_a?(Dry::Types::Definition)
|
|
26
77
|
Types::Array.member(type)
|
|
27
78
|
end
|
|
28
79
|
end
|
|
80
|
+
# rubocop:enable Naming/MethodName
|
|
29
81
|
|
|
30
82
|
# Types for schema definitions
|
|
31
83
|
#
|
data/lib/hanami/model/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hanami-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.0.
|
|
4
|
+
version: 1.1.0.rc1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luca Guidi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-10-
|
|
11
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: hanami-utils
|
|
@@ -16,14 +16,34 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - '='
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.1.0.
|
|
19
|
+
version: 1.1.0.rc1
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - '='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.1.0.
|
|
26
|
+
version: 1.1.0.rc1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rom
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.3'
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: 3.3.2
|
|
37
|
+
type: :runtime
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - "~>"
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '3.3'
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 3.3.2
|
|
27
47
|
- !ruby/object:Gem::Dependency
|
|
28
48
|
name: rom-sql
|
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -31,6 +51,9 @@ dependencies:
|
|
|
31
51
|
- - "~>"
|
|
32
52
|
- !ruby/object:Gem::Version
|
|
33
53
|
version: '1.3'
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: 1.3.5
|
|
34
57
|
type: :runtime
|
|
35
58
|
prerelease: false
|
|
36
59
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -38,6 +61,9 @@ dependencies:
|
|
|
38
61
|
- - "~>"
|
|
39
62
|
- !ruby/object:Gem::Version
|
|
40
63
|
version: '1.3'
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 1.3.5
|
|
41
67
|
- !ruby/object:Gem::Dependency
|
|
42
68
|
name: rom-repository
|
|
43
69
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,14 +84,14 @@ dependencies:
|
|
|
58
84
|
requirements:
|
|
59
85
|
- - "~>"
|
|
60
86
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
87
|
+
version: 0.11.0
|
|
62
88
|
type: :runtime
|
|
63
89
|
prerelease: false
|
|
64
90
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
91
|
requirements:
|
|
66
92
|
- - "~>"
|
|
67
93
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
94
|
+
version: 0.11.0
|
|
69
95
|
- !ruby/object:Gem::Dependency
|
|
70
96
|
name: concurrent-ruby
|
|
71
97
|
requirement: !ruby/object:Gem::Requirement
|