Skip to content

MissingRangeKey when destroying associated objects #501

Open
@thomaswitt

Description

@thomaswitt

Let's say I've got two simple models:

class Company
  include Dynamoid::Document

  table name: :company,
        key: :name,
        capacity_mode: :on_demand
  range :metadata

  has_many :reports
end
class Report
  include Dynamoid::Document

  belongs_to :company

  field :content

end

Now I'll create a company (c = Company.create(name: 'test', metadata 'COMPANY#CA#LOSANGELES')) and create an association with it (r = c.report.create(content: 'this is my report')). Works fine.

Now I want to delete the report, which will lead to an error: p.destroy /Users/me/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/dynamoid-3.7.0/lib/dynamoid/finders.rb:165:in _find_by_id': Dynamoid::Errors::MissingRangeKey (Dynamoid::Errors::MissingRangeKey). Same error when I call c.report.first.destroy`.

What happens in DynamoDB, the report in the reports table will be deleted, but not from the company table. Why? I guess it has to do with having a combined range key in the Company table, so you can't locate the parent object. But how do I supply the range key to the destroy function?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions