rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.08k stars 161 forks source link

Overridding attributes in auto-structs results in duplicated attributes #491

Closed solnic closed 5 years ago

solnic commented 6 years ago
module Entities
  class User < ROM::Struct
    attribute :login, Types::String
  end
end

class UserRepo < ROM::Repository[:users]
  struct_namespace Entities

  def by_id(id)
    users.by_pk(id).one
  end
end

user = rom.relations[:users]
  .changeset(:create, login: 'jane@doe.org', email: 'jane@doe.org')
  .commit

repo = UserRepo.new(rom)

repo.by_id(1)
# => #<Entities::User login="jane@doe.org" id=1 login="jane@doe.org" email="jane@doe.org">

Notice duplicated login in the inspected user. This is either a bug in the way we set up Equalizer in dry-struct OR we actually end up with the same attribute defined multiple times (which would be way worse).

flash-gordon commented 6 years ago

This is a bug in dry-struct. https://github.com/dry-rb/dry-struct/blob/v0.4.0/lib/dry/struct/class_interface.rb#L73 It is fixed in master but rom isn't compatible with it. We could cut a branch from v0.4.0 if needed

solnic commented 6 years ago

ahh OK, could we push 0.4.1 with just this fix (or any other changes that are safe to have in this release)?

flash-gordon commented 6 years ago

we could, this will be a separate fix though since we don't have this problem in master as we don't have that code at all :)

solnic commented 6 years ago

OK, so I guess this can wait for the 5.0 upgrade, unless somebody would like to fix it in dry-struct 0.4.x