Search code examples
rubysequel

Dataset Graph with separate hashes per table


The Sequel documentation states that

Dataset graphing changes the dataset to yield hashes where keys are table name symbols and values are hashes representing the columns related to that table. https://github.com/jeremyevans/sequel/blob/master/lib/sequel/dataset/graph.rb#L5

I'd really like to use this behaviour, so when I do something like;

db[:referrals].graph(:users, :id => :user_id).first

I would get;

{referrals: {id: 1, name: 'Joe', user_id: 10}, users: {id: 10, name: 'Dave'}}

However, what is returned is more like;

{id: 1, name: 'Joe', user_id: 10, users_name: 'Dave'}

I can't see any obvious way to change this in the docs. Am I missing something blindingly obvious (wouldn't be the first time).


Solution

  • The docs need to be updated (I'll take care of that shortly). You now need to use the graph_each extension to get the splitting.