Forum: Ruby on Rails Join two DynamoDb Tables from AWS

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
18146f68e66b36cc3f9b14289fd39d44?d=identicon&s=25 Jeff Whut (jwhut)
on 2017-01-28 12:04
I need to join two tables with aws dynamodb. Currently I am querying the
one just fine, but I need to bring in this other table, but I'm having a
heck of a time finding a simple example for dynamodb with rails.

        client =
        response = client.scan(table_name: 'db_current')
        @items = response.items

{"machine_id"=>"pc-123435", "type_id"=>"t-56778"}

{"description"=>"Dell 5 Dev Computer", "Name"=>"Dell",

I thought I might have to make two:

        client =
        db_c = client.scan(table_name: 'db_current')
        @c_items = db_c.items

        client =
        db_t = client.scan(table_name: 'db_type')
        @t_items = db_c.joins(db_t['type_id'])  <=== then merge them

But sadly no luck.

I'm looking for suggestions.  I'd prefer to keep it simple to really
understand (I don't want to pull in ActiveRecord or things like that
18146f68e66b36cc3f9b14289fd39d44?d=identicon&s=25 Jeff Whut (jwhut)
on 2017-01-30 03:36
I ended up doing it this way. There is probably a more elegant solution
for those that are familiar with Ruby... that I am not.

basically for each of the items in the first hash array (table), I use
the ID from that one to filter on the item for the 2nd hash array.
Merging them in the process. then appending to a final destination which
I'll use for my UI.

    @c_by_id =

    @b_items.each do |item|
        pjoin = @c_items.first {|h| h['b_id'] == item['b_id']}
        newjoin = item.merge(pjoin)
This topic is locked and can not be replied to.