These are chat archives for hanami/chat

22nd
May 2019
Maks
@maks_ah_gitlab
May 22 2019 06:24 UTC

Hi all! Could someone please point me where I can find how to define custom schema on entities with attributes of associated records? I have User that has one Address so in Address entity:

class Address < Hanami::Entity
  attributes do
    attribute :id, Types::Int
    attribute :street, Types::String
    ....
    attribute :user, Types::Entity(User)
  end
end

There are two problems:

  1. Hanami does not see User constant unless I do require_relative './user' - is there any way to solve it on some global level so I do not need to include it in each entity?
  2. When I try to get Address from db, user attribute is not set. I am getting it via:
    AddressRepository.new.aggregate(:user).where(id: 1).map_to(Address).one
    If I remove custom schema completely - everything works fine :/
Paweł Świątkowski
@katafrakt
May 22 2019 07:46 UTC
I think entity classes are loaded in alphabetical order. I'll leare require_realtive, because it states on the top of the file what are it's dependencies.
Maks
@maks_ah_gitlab
May 22 2019 07:57 UTC
Thanks for your response @katafrakt. Could you please clarify what do you mean by leare?
The problem with requiring here is that requiring some constant like User may have defined other requires inside that user.rb. So we'll have strange non existing constants lookup
Maks
@maks_ah_gitlab
May 22 2019 08:22 UTC
I have another question though regarding logging
is there any possibility to disable query logs in stdout on INFO level like:
[bookshelf] [INFO] [2017-02-11 15:42:48 +0100] (0.000381s) SELECT "id", "title", "created_at", "updated_at" FROM "books" WHERE ("book"."id" = '1') ORDER BY "books"."id"
Sebastian Kreft
@sebastian-kreft
May 22 2019 08:28 UTC

Hi :wave:
I am new in Hanamirb, I have one app on production since couple of days - works like a charm. But I would like to tune logging settings. I would like to hide SQL queries from log entries on production, is it possible?

environment :production do
  model do
    logger level: :error
  end
end

:arrow_up: is the way to go? Experimented with similar on my local setup but still seeing SQL statements.

Similar question was asked before, but sadly with no answer :( I’m also curious about this one.

Paweł Świątkowski
@katafrakt
May 22 2019 09:14 UTC
@maks_ah_gitlab sorry, leare -> leave ;)
But I'm afraid I don't understand the problem with non-existing constants lookup
Maks
@maks_ah_gitlab
May 22 2019 09:29 UTC

@katafrakt For example if you have such:

# user.rb
require_relative './address'

class User < Hanami::Entity
  attributes do
    attribute :id, Types::Int
    ...
    attribute :address, Types::Entity(Address)

and associated Address:

# address.rb
require_relative './user'

class User < Hanami::Entity
  attributes do
    attribute :id, Types::Int
    ...
    attribute :user, Types::Entity(User)

Then Hanami loads it like - Address first, then inside address.rb requires relative user.rb which has again require_relative './address'. So this results in uninitialized constant Address::User