Git Product home page Git Product logo

Comments (9)

 avatar commented on August 28, 2024

Related to #79. I upgraded to rom-sql#master. Now I get the following error message. Also upgrading to rom#master, rom-repository#master doesn't solve the problem.

NoMethodError: undefined method `merge' for #<ROM::Struct[Department] id=1 name="department1">
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/association/one_to_one.rb:37:in `associate'
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/plugin/associates.rb:69:in `block in execute'
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/plugin/associates.rb:68:in `map'
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/plugin/associates.rb:68:in `each'
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/plugin/associates.rb:68:in `map'
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/plugin/associates.rb:68:in `execute'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/command.rb:110:in `call'
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/commands/error_wrapper.rb:12:in `call'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/commands/lazy/create.rb:17:in `call'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/commands/graph.rb:64:in `block in call'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/commands/graph.rb:61:in `map'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/commands/graph.rb:61:in `call'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/commands/composite.rb:18:in `call'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_proxy.rb:14:in `call'
/home/user1/project/lib/script/repos/user_repo.rb:18:in `create_with_department'
/home/user1/project/lib/script/cli_runner.rb:25:in `parse_data'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
bin/script.rb:7:in `<top (required)>'

from rom-sql.

 avatar commented on August 28, 2024

Switching the implementation to create the user first and then update the department, results in a different exception:

require 'script/container'
require 'script/repos/role_repo'
require 'script/repos/user_repo'
require 'script/repos/department_repo'
require 'script/container'
require  'thor'

module Script
  class CliRunner < Thor
    desc 'parse_data', 'Parse data from files'
    def parse_data
      role_repo = RoleRepo.new(Script::CONTAINER)
      department_repo = DepartmentRepo.new(Script::CONTAINER)
      user_repo = UserRepo.new(Script::CONTAINER)

      employee_role = role_repo.create(name: 'employee')
      manager_role = role_repo.create(name: 'manager')
      department = department_repo.create(name: 'department1')
      user = user_repo.create(name: 'user1')

      # department_repo.add_user(name: 'department1', user: user)
      department_repo.add_user(name: 'department1', users: [user])
    end

    default_command :parse_data
  end
end

The department repo definition:

require 'script/department'

module Script
  class DepartmentRepo < ROM::Repository[:departments]
    relations :users

    commands :create, update: :by_pk

    def query(conditions)
      departments.where(conditions).as(Department)
    end

    def by_id(id)
      departments.fetch(id)
    end

    def add_user(department)
      command(:update, aggregate(:users)).call(department)
    end
  end
end

This is the exception I always get.

NameError: undefined local variable or method `associations' for ROM::SQL::Commands::Update[:users]:Class
Did you mean?  associates
/home/user1/.rvm/gems/ruby-2.3.0/bundler/gems/rom-sql-1c11f057dc0c/lib/rom/sql/plugin/associates.rb:106:in `associates'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:182:in `setup_associates'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:155:in `block in register_command'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-2.0.0/lib/rom/commands/class_interface.rb:73:in `create_class'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:151:in `register_command'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:115:in `visit_relation'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:98:in `visit'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:126:in `block in visit_header'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:126:in `map'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:126:in `visit_header'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:98:in `visit'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:106:in `visit_relation'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:98:in `visit'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:45:in `block in []'
/home/user1/.rvm/gems/ruby-2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:133:in `block in fetch_or_store'
/home/user1/.rvm/gems/ruby-2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:122:in `fetch'
/home/user1/.rvm/gems/ruby-2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:132:in `fetch_or_store'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository/command_compiler.rb:38:in `[]'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository.rb:212:in `compile_command'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository.rb:138:in `block in command'
/home/user1/.rvm/gems/ruby-2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:133:in `block in fetch_or_store'
/home/user1/.rvm/gems/ruby-2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:122:in `fetch'
/home/user1/.rvm/gems/ruby-2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:132:in `fetch_or_store'
/home/user1/.rvm/gems/ruby-2.3.0/gems/rom-repository-0.3.1/lib/rom/repository.rb:137:in `command'
/home/user1/project/lib/script/repos/department_repo.rb:20:in `add_user'
/home/user1/project/lib/script/cli_runner.rb:27:in `parse_data'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
/home/user1/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
bin/script.rb:7:in `<top (required)>'

from rom-sql.

solnic avatar solnic commented on August 28, 2024

Thanks for this detailed report, that's very helpful. I'll look into that.

from rom-sql.

solnic avatar solnic commented on August 28, 2024

btw:

    def add_user(department)
      command(:update, aggregate(:users)).all(department)
    end

^^ should be :create instead of :update and call instead of all

from rom-sql.

 avatar commented on August 28, 2024

@solnic Thanks. If you need more information, don't hesitate to ping me.

@solnic Sure, it was meant to be #call. Fixed in comment.

But why #create instead of #update? I created the department earlier and then change it to add more users.

department = department_repo.create(name: 'department1')
user = user_repo.create(name: 'user1')

# department_repo.add_user(name: 'department1', user: user)
# department_repo.add_user(name: 'department1', users: [user])
# department_repo.add_user(department, users: [user])
# department_repo.add_user(name: department.name, users: [user])

I'm not sure which one is the correct one to update an existing department.

from rom-sql.

 avatar commented on August 28, 2024

BTW: I love the flexibility of rom, but it's a bit confusing for beginners. :-) Is there an ongoing discussion about the "style" you should use with rom anywhere?

I found quite a few different possibilities on the net, which all seem to work. Shall I open another issue for that? At least some more documentation on that would be helpful.

What was a bit problematic for me, is the order in which things needs to be initialized. I was not able to reproduce the problem I had, along with the problems above I faced a ROM::Repository-constant missing error. After adding require 'rom/repository' to my repo-files the error went away. I cannot provide more information on that topic for you. Does it makes sense to open a ticket for that?

from rom-sql.

solnic avatar solnic commented on August 28, 2024

I love the flexibility of rom, but it's a bit confusing for beginners. :-)

This will improve once rom-repository reaches 1.0.0 :)

Is there an ongoing discussion about the "style" you should use with rom anywhere?

Nope, but feel free to start one on discuss.rom-rb.org

What was a bit problematic for me, is the order in which things needs to be initialized. I was not able to reproduce the problem I had, along with the problems above I faced a ROM::Repository-constant missing error. After adding require 'rom/repository' to my repo-files the error went away. I cannot provide more information on that topic for you. Does it makes sense to open a ticket for that?

Nothing requires rom/repository for you, so you need to require that file yourself. This is not a bug. Require What You Require™ :)

from rom-sql.

 avatar commented on August 28, 2024

Nothing requires rom/repository for you, so you need to require that file yourself.

Ah, ok. Good to know. Was not aware of that. Thanks.

from rom-sql.

solnic avatar solnic commented on August 28, 2024

I'm closing this one. Feel free to re-open or report a new issue if something needs to be done or discussed.

from rom-sql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.