Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to load a custom struct through Rails autoloading #83

Open
art-solopov opened this issue Sep 25, 2017 · 4 comments
Open

Fails to load a custom struct through Rails autoloading #83

art-solopov opened this issue Sep 25, 2017 · 4 comments

Comments

@art-solopov
Copy link

How to reproduce

user_repo = UserRepository.new(ROM.env)
u = user_repo.users.first
puts u.login

Expected

Some string printed

Actual

ROM::Struct::MissingAttribute: undefined method `login' for #<Entities::User:0x005644dfbd85b0> (not loaded attribute?)

Additional info

This seems to be an autoloading issue since setting config.eager_load to true produces the expected result.

The full code of the Rails project can be found here.

@cflipse
Copy link
Contributor

cflipse commented Oct 12, 2017

Unfortunately, the way that the loading structure works in ROM-repository requires the entities module to already exist; otherwise, it will simply create a new one -- which will kill the Rails const_missing logic.

The best recommendation I have for you is to create a file app/models/entities.rb and have that file either require all of your entities, or register them with autoload:

module Entities
  autoload :user 'entities/user'
end

Then require 'entities' at the start of your repository files. It's off the Rails way, I know, and I'll need to make sure that the docs do a better job of mentioning this -- though this is a relatively new feature for rom-repository, and I'm not sure all the docs have been written for it yet.

@anthony-bernardo
Copy link

anthony-bernardo commented Mar 22, 2018

Did you resolve that ?
I cannot fix this

Edit :

It's working with (but not for repository)

module Entities
  require 'entities/user'
end

@anthony-bernardo
Copy link

anthony-bernardo commented Mar 22, 2018

There is 2 issues :

  1. Hot reloading don't work
  2. Repository don't work

I'm trying to integrate rom on Rails, for now here my result : https://github.com/xero88/poc-rom-rb

@cflipse
Copy link
Contributor

cflipse commented Mar 22, 2018

  1. Please file a different ticket
  2. I need more information "Repository don't work"
  3. For debugging and advice (ie, until we know what the actual error is) please use https://discourse.rom-rb.org/
  4. Looking at your gemfile, I see that you're using Dry::AutoInject, and Spring. Try it without spring, and possibly try it without auto inject, if that's used in any of the repo or related. Both of those screw with the load process, and it may not be in compatible ways. If still failing, open a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants