Giter Club home page Giter Club logo

Comments (19)

solnic avatar solnic commented on August 25, 2024

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.

akirill0v avatar akirill0v commented on August 25, 2024

@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.

solnic avatar solnic commented on August 25, 2024

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.

solnic avatar solnic commented on August 25, 2024

ps. sorry I accidentally closed this issues and sent a half-written comment which I just edited and added the missing part :)

from rom.

solnic avatar solnic commented on August 25, 2024

btw are you using ROM for something real or just playing with it?

from rom.

akirill0v avatar akirill0v commented on August 25, 2024

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.

akirill0v avatar akirill0v commented on August 25, 2024

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.

solnic avatar solnic commented on August 25, 2024

@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.

solnic avatar solnic commented on August 25, 2024

@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.

akirill0v avatar akirill0v commented on August 25, 2024

@solnic I will try it tomorrow and I will inform you about the results, of course )))

from rom.

solnic avatar solnic commented on August 25, 2024

@saratovsource thanks, I'm adding your example to rom-demo project just to see if it works :)

from rom.

solnic avatar solnic commented on August 25, 2024

@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.

akirill0v avatar akirill0v commented on August 25, 2024

@solnic Many thanks for the example! I would be very happy if the same example was for wrap))

from rom.

solnic avatar solnic commented on August 25, 2024

@saratovsource sure, I just added "wrap" example here :)

from rom.

dnesteryuk avatar dnesteryuk commented on August 25, 2024

@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.

solnic avatar solnic commented on August 25, 2024

Do you have your adapter on github?

from rom.

solnic avatar solnic commented on August 25, 2024

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.

dnesteryuk avatar dnesteryuk commented on August 25, 2024

@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.

solnic avatar solnic commented on August 25, 2024

@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)

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.