• Best way to create hash of hashes

    From Sayth Renshaw@21:1/5 to All on Fri Jun 24 18:50:35 2016
    Hi

    What is the best way when collecting data to create a has of hashes?

    So say this was my expected result.

    { Id:123 { id:1, name:John},{id:2, name: Sarah}}

    So that I am saying Sarah and John are members of group id: 123.

    Thanks

    Sayth

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to Sayth Renshaw on Sat Jun 25 12:16:12 2016
    On 25.06.2016 03:50, Sayth Renshaw wrote:

    What is the best way when collecting data to create a has of hashes?

    So say this was my expected result.

    { Id:123 { id:1, name:John},{id:2, name: Sarah}}

    This is not a valid representation of a Hash. Which of these do you want?

    irb(main):001:0> { 'Id:123' => [{id:1, name:'John'}, {id:2, name:'Sarah'}]}
    {"Id:123"=>[{:id=>1, :name=>"John"}, {:id=>2, :name=>"Sarah"}]}

    irb(main):002:0> { Id:123, members: [{id:1, name:'John'}, {id:2, name:'Sarah'}]}
    {:Id=>123, :members=>[{:id=>1, :name=>"John"}, {:id=>2, :name=>"Sarah"}]}

    ...

    So that I am saying Sarah and John are members of group id: 123.

    That depends on your input and how you access it.

    Kind regards

    robert


    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sayth Renshaw@21:1/5 to All on Sat Jun 25 03:47:12 2016
    This is not a valid representation of a Hash. Which of these do you want?

    irb(main):001:0> { 'Id:123' => [{id:1, name:'John'}, {id:2, name:'Sarah'}]}
    {"Id:123"=>[{:id=>1, :name=>"John"}, {:id=>2, :name=>"Sarah"}]}

    irb(main):002:0> { Id:123, members: [{id:1, name:'John'}, {id:2, name:'Sarah'}]}
    {:Id=>123, :members=>[{:id=>1, :name=>"John"}, {:id=>2, :name=>"Sarah"}]}

    ...

    So that I am saying Sarah and John are members of group id: 123.

    That depends on your input and how you access it.

    Kind regards

    robert


    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    Is there a particular benefit of one over the other? I want to be able to keep the relation between ids and descendant nodes and then put this into a database, is one more suitable than the other?

    Thanks

    Sayth

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to Sayth Renshaw on Sat Jun 25 14:19:25 2016
    On 25.06.2016 12:47, Sayth Renshaw wrote:

    Is there a particular benefit of one over the other? I want to be
    able to keep the relation between ids and descendant nodes and then put this into a database, is one more suitable than the other?

    Of course. But it depends on the usage. You need to make up your mind
    how you want to go about things. Since we do not know what database you
    want to put that into, how the schema looks (if it has one), what the
    source of data is and all the other circumstances, the only one who can realistically answer that question at the current point in time is you.

    Kind regards

    robert


    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sayth Renshaw@21:1/5 to All on Sat Jun 25 08:27:31 2016
    Hi

    The data I will be collecting from XML has a snowflake schema based around, though there are changes I want to make from first version.

    At this stage i just want to ensure I maintain the relationship of each person and id to the event id and will create some json files to play with charts and display before I parse all files and push to database.

    Cheers

    Sayth

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to Sayth Renshaw on Sun Jun 26 00:26:27 2016
    On 25.06.2016 17:27, Sayth Renshaw wrote:

    The data I will be collecting from XML has a snowflake schema based
    around, though there are changes I want to make from first version.

    I am not sure how a snowflake schema looks in XML. Or is that the
    target DB?

    At this stage i just want to ensure I maintain the relationship of
    each person and id to the event id and will create some json files to
    play with charts and display before I parse all files and push to
    database.

    Wouldn't it be sufficient then to store the event id in every person?
    And what do you need JSON for when you read from XML and store in a (presumably) relational DB?

    Cheers

    robert

    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)