Comments (9)
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.
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.
Thanks for this detailed report, that's very helpful. I'll look into that.
from rom-sql.
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.
@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.
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.
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.
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.
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)
- Legacy schema
- Multi_insert returns more results than expected in some specific conditions HOT 5
- Attribute methods not available *within* a relation, but are *outside* of a relation HOT 4
- create returns nil for custom primary keys HOT 4
- OVER clause lost from row_number functions. HOT 9
- Postgres Upsert command does not support specifying index predicate for partial unique indices
- Translate symbols in a hash applied to `Relation#where` to attributes HOT 1
- "undefined method `stream'" when trying to use the `:pg_streaming` plugin HOT 2
- Multi-Schema database HOT 1
- Relation#multi_insert fails with blob data HOT 4
- Add a custom `Create` command for sqlite
- Use of projection dsl is not available in Relation#exclude
- Support for ANY in condition DSL HOT 5
- Error when attempting to join relations across different databases HOT 3
- [Migration] schema_migrations and schema_info tables error HOT 2
- Support virtual columns in `union` queries
- Problem with :create command and custom types HOT 2
- `by_pk` causes stack overflow when used with single primary key while table define composite primary key
- SQLite doesn't cast 1/0 to true and false HOT 5
- Relation#last removes combines HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rom-sql.