Last active
August 29, 2015 13:59
-
-
Save solnic/10553929 to your computer and use it in GitHub Desktop.
ROM mapper with anima model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rom' | |
require 'anima' | |
class User | |
include Anima.new(:id, :name, :tasks) | |
end | |
class Task | |
include Anima.new(:title) | |
end | |
user_mapper = ROM::Mapper.build do | |
model User | |
map :id | |
map :name, from: :user_name | |
end | |
task_mapper = ROM::Mapper.build do | |
model Task | |
map :title | |
end | |
puts user_mapper.group(tasks: task_mapper). | |
load(id: 1, user_name: 'Piotr', tasks: [{title: 'Task 1'}, {title: 'Task 2'}]).inspect | |
#<User id=1 name="Piotr" tasks=[#<Task title="Task 1">, #<Task title="Task 2">]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment