From 4125d4a70b4e3d7d5c2210324f599e97281a0991 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Tue, 11 Jun 2024 23:46:27 -0600 Subject: [PATCH 1/4] Fix examples --- core/lib/rom/struct.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/lib/rom/struct.rb b/core/lib/rom/struct.rb index ecd2ea677..7d34a8adb 100644 --- a/core/lib/rom/struct.rb +++ b/core/lib/rom/struct.rb @@ -33,6 +33,8 @@ module ROM # end # # class UserRepo < ROM::Repository[:users] + # schema(infer: true) + # auto_struct true # end # # user_repo = UserRepo.new(rom) @@ -43,11 +45,11 @@ module ROM # # # see struct's schema attributes # - # # model.schema.key(:id) - # # => #]> + # model.schema.key(:id) + # # => #]> # # model.schema[:name] - # # => # | Nominal meta={source: :users}>]> + # # => # | Nominal meta={alias: nil, source: :users}>]> # # @example passing a namespace with an existing parent class # module Entities @@ -63,6 +65,7 @@ module ROM # end # # user_repo = UserRepo.new(rom) + # user_repo.users.insert(name: "Jane") # user = user_repo.users.by_pk(1).one! # user.name # => "Jane" # user.upcased_name # => "JANE" From 3b4b54b0d6e7257787e617e853c74d2eecce4c06 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Tue, 11 Jun 2024 23:49:40 -0600 Subject: [PATCH 2/4] Add bold and 'NOTE' about ROM structs being anonymous --- core/lib/rom/struct.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/lib/rom/struct.rb b/core/lib/rom/struct.rb index 7d34a8adb..80808da5b 100644 --- a/core/lib/rom/struct.rb +++ b/core/lib/rom/struct.rb @@ -17,9 +17,10 @@ module ROM # about attribute types returned from relations, thus can be introspected to build # additional functionality when desired. # - # There is a caveat you should know about when working with structs. Struct classes - # have names but at the same time they're anonymous, i.e. you can't get the User struct class - # with ROM::Struct::User. ROM will create as many struct classes for User as needed, + # *NOTE*: There is a caveat you should know about when working with ROM structs. + # Struct classes have names but at the same time they're anonymous, + # i.e. you can't get the User struct class with ROM::Struct::User. + # ROM will create as many struct classes for User as needed, # they all will have the same name and ROM::Struct::User will be the common parent class for # them. Combined with the ability to provide your own namespace for structs this enables to # pre-define the parent class. From 4576b7e8f384498f223e875d278663cd3ad02837 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Wed, 12 Jun 2024 09:44:47 -0600 Subject: [PATCH 3/4] Fix config --- core/lib/rom/struct.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/lib/rom/struct.rb b/core/lib/rom/struct.rb index 80808da5b..79c3567cf 100644 --- a/core/lib/rom/struct.rb +++ b/core/lib/rom/struct.rb @@ -31,11 +31,14 @@ module ROM # primary_key :id # column :name, String # end + # + # conf.relation(:users) do + # schema(infer: true) + # auto_struct true + # end # end # # class UserRepo < ROM::Repository[:users] - # schema(infer: true) - # auto_struct true # end # # user_repo = UserRepo.new(rom) From 3bfe3efab3cdfeafabb5b4f107c7108bec287509 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Wed, 12 Jun 2024 09:48:57 -0600 Subject: [PATCH 4/4] Remove alias from types output --- core/lib/rom/struct.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/rom/struct.rb b/core/lib/rom/struct.rb index 79c3567cf..a1ff313fd 100644 --- a/core/lib/rom/struct.rb +++ b/core/lib/rom/struct.rb @@ -50,10 +50,10 @@ module ROM # # see struct's schema attributes # # model.schema.key(:id) - # # => #]> + # # => #]> # # model.schema[:name] - # # => # | Nominal meta={alias: nil, source: :users}>]> + # # => # | Nominal meta={source: :users}>]> # # @example passing a namespace with an existing parent class # module Entities