rom-bot on master
[devtools] sync (compare)
flash-gordon on master
Bump version to 4.0.0 and updat… (compare)
flash-gordon on master
Use keywords in transaction met… Merge pull request #392 from ro… (compare)
flash-gordon on transaction-options
flash-gordon on transaction-options
Use keywords in transaction met… (compare)
rom-bot on master
[devtools] sync (compare)
rom-bot on master
[devtools] sync (compare)
solnic on master
Update changelog.yml (compare)
options = {
test: true,
single_threaded: persistence.config.env == :test,
after_connect: inject_pub_connections,
max_connections: 30
}
my config
DatabaseCleaner[:rom_sql]
:sequel
to use it
ROM.env.relations[:users]
-- this seems odd to me, have I missed something completely?
hey all. i got a question regarding rom in hanami, which the hanami chat couldn't help me with so far:
i have some trouble constructing a nested dataset for an index view.
i have these associated objects: subscription has plan, plan has fee. besides, subscription has client. in my index i need data from all four objects.
i'm trying to to figure out how to create a query which will give me the nested datastructure that i will need. based on the examples in the documentation i can already get either subscription with client or subscription with plan.
def all_with_clients_and_plans
aggregate(:clients, :plans)
end
this is how far i got, as clients and plans are directly associated with subscription. handling the resulting ROM::Struct as an array by calling each on it is also fairly self explanatory. however, i do not understand how i can add the missing fee data that is associated to plan, or the missing client, all in the same query, or how i can have multiple queries and then construct the right array from that.
i think what i need is some sort of recursive aggregate. is that correct or am i doing something really wrong? i feel like i am coupling stuff too tighlyt, but i certainly need it in the index view. the question really is where i should put that query logic, i think.
there are samples of wrap and combine mentioned in the rom docu, but those don't seem to really do anything on this particular set. having read a bit more about the rom docs, i think i might actually be able to achieve this with custom views, as described here https://rom-rb.org/current/learn/sql/associations/
however, when adding this to my association block, there's really not any effect. checking in the source, it seems that everything in the associations block is just handed down to ROM so i must be doing something wrong here, or misunderstanding how this works.
this is how i've tried custom views
class SubscriptionRepository < Hanami::Repository
associations do
belongs_to :client
has_many :plans, view: :with_fees
end
def all_with_clients_and_plans
aggregate(:clients, :plans)
end
end
class PlanRepository < Hanami::Repository
associations do
has_one :agreement
belongs_to :fee
belongs_to :subscription
end
def with_fees
aggregate(:fees)
end
end
however, all i'm getting on SubscriptionRepository.new.all_with_clients_and_plans
isNoMethodError: undefined method
with_fees' for #<#<Class:0x0000562a00cdaca0>:0x0000562a00bcadb0>`
Hi,
how to use rom-rb and dry-system-rails (dry-container and dry-auto_inject)?
config/initializers/system.rb
Dry::System::Rails.container do
config.auto_register << 'app/repositories'
config.auto_register << 'app/services'
end
app/services/create_user.rb
class CreateUser
include Blog::Import['user_repository']
def call(user_attrs)
users_repository.create(user_attrs)
end
end
app/repositories/user_repository.rb
class UserRepository < ROM::Repository[:users]
end
class Conversations < ROM::Relation[:sql]
schema do
attribute :id, Types::Integer
attribute :sender_id, Types::Integer
attribute :receiver_id, Types::Integer
attribute :created_at, Types::DateTime
attribute :updated_at, Types::DateTime
associations do
has_many :messages
belongs_to :profiles, as: :sender, foreign_key: :sender_id
belongs_to :profiles, as: :receiver, foreign_key: :receiver_id
end
end
end
class Profiles < ROM::Relation[:sql]
schema do
attribute :id, Types::Integer
attribute :name, Types::String
attribute :type, Types::String
associations do
has_many :conversations
has_many :platform_details
end
end
end