Comments (19)
you'll be able to use virtus objects with rom, don't worry. I'm working on integrating morpher with rom which eventually became our mapping backend. Once that's done you'll be able to use virtus objects on top, however, morpher will take care of the mapping so virtus' attribute mapping will be redundant.
from rom.
@solnic it awesome gem! But how about Morpher? Now it fully integrated?
I can not understand how the changed scheme and mapping in this case?
I have:
class Application
include ActiveModel.model
include Equalizer.new :id, :name
attr_accessor :id, :name
end
class Slot
include ActiveModel::Model
include Equalizer.new(:id, :name, :applications)
attr_accessor :id, :name, :applications
end
# mapping
#...
applications do
model Application
map :id, from: :uuid # other key in json
map :name, from: :title # other key in json
end
slots do
model Slot
map :id, :name, :applications
end
Slot
has collection of Application
How to define simple schema and collection type? In Virtus is Array[Application]
, but it not working now with Morpher and Axiom attributes...
Thanks for the help.
from rom.
Currently the dsl to define wrapped or groupped relations is half-done. I can try to do it for 0.2.0 release though.
Once ready this is more or less how you'll be able to do that:
schema do
base_relation(:applications) do
repository :something
attribute :uuid, String
attribute :title, String
attribute :slot_id, Integer # this is just my assumption
end
base_relation(:slots) do
repository :something
attribute :id, Integer
attribute :name, String
# this means whenever fetching slots also join and group applications
group(:applications => applications)
end
end
mapping do
relation(:applications) do
model Application
map :id, from: :uuid # other key in json
map :name, from: :title # other key in json
end
relation(:slots) do
model Slot
map :id, :name, :applications
end
end
Settings this up like that sets up an aggregate though, if you want to have those models separate and group things on demand you can do that too via join/group operations.
from rom.
ps. sorry I accidentally closed this issues and sent a half-written comment which I just edited and added the missing part :)
from rom.
btw are you using ROM for something real or just playing with it?
from rom.
Yep, I use ROM in real project for transfer data from different sources (eg. json api and other app clients through its gems). With base types and flatten types (not collections and hashes) it perfect work...
For example, applications are taken from the API, and slots - from gem.
from rom.
I tried to do as you have shown, but the mapper can not dump the "Applications" (they are still objects, not tuples).
I found your example in the tests (https://github.com/rom-rb/rom/blob/master/spec/integration/grouped_mappers_spec.rb) - is virtually a clone of my task. Could you add / edit the test to the group was in the scheme (as in the last example of this issue)? It possible? Thanks.
I found cool spec) https://github.com/rom-rb/rom/blob/master/spec/integration/schema_definition_spec.rb
from rom.
@saratovsource I suppose this spec shows exactly how you could achieve what you need (it's the same as your case). This isn't using the schema/mapping DSL I showed you above though but that shouldn't matter much.
from rom.
@saratovsource btw I'd really appreciate if you could try to use rom from master in your app and let me know if it works for you
from rom.
@solnic I will try it tomorrow and I will inform you about the results, of course )))
from rom.
@saratovsource thanks, I'm adding your example to rom-demo project just to see if it works :)
from rom.
@saratovsource I'm not sure how closely it matches your case but here's an example using sqlite and slot/applications models loaded via join & group
from rom.
@solnic Many thanks for the example! I would be very happy if the same example was for wrap))
from rom.
@saratovsource sure, I just added "wrap" example here :)
from rom.
@solnic I played a bit with your solution (group
and wrap
methods), but it doesn't work for me :( Your example works well for relation DB, but for my custom storage it doesn't. Can you provide some example (it is better to have demo example) which will allow me to work with such response from Git API:
https://developer.github.com/v3/repos/
[
{
"id": 1296269,
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"description": "This your first repo!",
"private": false,
"fork": true,
"url": "https://api.github.com/repos/octocat/Hello-World",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"git_url": "git://github.com/octocat/Hello-World.git",
"ssh_url": "[email protected]:octocat/Hello-World.git",
"svn_url": "https://svn.github.com/octocat/Hello-World",
"mirror_url": "git://git.example.com/octocat/Hello-World",
"homepage": "https://github.com",
"language": null,
"forks_count": 9,
"stargazers_count": 80,
"watchers_count": 80,
"size": 108,
"default_branch": "master",
"open_issues_count": 0,
"has_issues": true,
"has_wiki": true,
"has_downloads": true,
"pushed_at": "2011-01-26T19:06:43Z",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z",
"permissions": {
"admin": false,
"push": false,
"pull": true
}
}
]
Current version of ROM works well with a simple data structure, but it doesn't when I have something more complicated. May be I didn't get something. Thank you!!!
from rom.
Do you have your adapter on github?
from rom.
btw wrap/group is designed for wrapping/grouping 2 relations. if your adapter returns a nested data structure like in this example than you might want to build a special mapper for it. I can show you how if that's the case.
from rom.
@solnic it is exactly my point, I don't need any new relation, I just need to map a nested data. I would appreciate if you show me an example how to do that. Thanks.
from rom.
@dnesteryuk gah sorry for getting back to you so late...here's a gist showing how to use standalone mappers
from rom.
Related Issues (20)
- AutoStruct does not respect type definition when creating HOT 9
- Relation with name `:schema' causes registration problems
- Relax freezing policy for `ROM::Configurable`
- Using Repository#transaction with non-default gateways HOT 2
- Fix Ruby 3.0 compatibility HOT 3
- Running tests raises 'Too many open files - getcwd (Errno::EMFILE)' HOT 1
- Inconsistency between Time formats in ROM::Changeset::PipeRegistry and ROM::Plugins::Command::Timestamps HOT 1
- Relation doesn't work in repository HOT 2
- delete: :by_pk in a repository breaks with timestamps plugin
- Associated entities are not mapped to their entity-classes in case of alias HOT 3
- Error when a relation with the name `options` exists. HOT 2
- Unable to modify the node of a combined assc. when a child of that assc. is combined.
- Aggregate write on self referencing relation not setting foreign key HOT 1
- Batch insert with one INSERT query HOT 7
- Fix multiple association block use to prevent ROM::AssociationSet registry error HOT 1
- Rails 7.1 incompatibility (Object#with) HOT 5
- Broken example code, unexpected auto_struct behavior HOT 3
- uninitialized constant ROM::Memory::Types::Int HOT 3
- Rails 7.1 Upgrade Causes map_with To Throw ArgumentError HOT 3
- Excessive memory use with many relations (>500) HOT 4
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.