Comments (1)
You must have a typo somewhere because the example works, I copied/pasted it from the docs and it worked:
require 'rom-repository'
rom = ROM.container(:sql, 'sqlite::memory') do |config|
config.default.create_table(:users) do
primary_key :id
column :name, String, null: false
column :email, String, null: false
end
config.default.create_table(:tasks) do
primary_key :id
foreign_key :user_id, :users
column :title, String, null: false
end
config.relation(:users) do
schema(infer: true) do
associations do
has_many :tasks
end
end
end
config.relation(:tasks) do
schema(infer: true) do
associations do
belongs_to :user
end
end
end
end
class UserRepo < ROM::Repository[:users]
def create_with_tasks(user)
users.combine(:tasks).command(:create).call(user)
end
end
user_repo = UserRepo.new(rom)
user = user_repo.create_with_tasks(
name: 'Jane',
email: '[email protected]',
tasks: [{ title: 'Task 1' }, { title: 'Task 2' }]
)
user.inspect
# #<ROM::Struct::User id=1 name="Jane" email="[email protected]" tasks=[#<ROM::Struct::Task id=1 user_id=1 title="Task 1">, #<ROM::Struct::Task id=2 user_id=1 title="Task 2">]>
from rom-rb.org.
Related Issues (20)
- Feedback on ROM - Changesets HOT 1
- The combination of `map_to` and `map_with` don't work as experted HOT 1
- Feedback on ROM - Rails Setup HOT 5
- Auto-struct with custom classes - undefined method HOT 2
- Feedback on ROM - Rails Setup
- Set up auto-deployment HOT 1
- Rom website has Content Security Policy errors in iframe HOT 3
- Missing docs for pagination plugin HOT 2
- Broken link in Advanced section
- Fix all broken links HOT 3
- Localisation: Brazilian Portuguese HOT 1
- Explain how auto-struct subclassing works
- Feedback on ROM - Status HOT 1
- Feedback on ROM - Mapping
- Feedback on ROM - Quick Start HOT 3
- Feedback on ROM - Relations & Structs HOT 3
- Unclear documentation
- The "Edit on Github" link on rom-rb.org quick-setup points to the old rom-rb/rom-core github repository. HOT 1
- HTTP examples don't work HOT 6
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-rb.org.