dynamoid icon indicating copy to clipboard operation
dynamoid copied to clipboard

How to make foreign key association?

Open kunalvashistordway opened this issue 5 years ago • 2 comments

class Workflow
  include Dynamoid::Document
  include SecureRandom

  table name: :workflows, key: :company_id

  range :api_name

  has_many :workflow_logs

  field :company_id, :integer
  field :api_name
  field :workflow_id, :string, default: SecureRandom.uuid
}
class WorkflowLog
  include Dynamoid::Document
  table name: :workflow_logs
  belongs_to :workflow, foreign_key: :workflow_id
  field :company_id, :integer
end

Workflow has primary partition key as company id and sort key api name, i want workflow_id to be foreign key for workflow logs, but its taking company_id value for workflow logs

kunalvashistordway avatar Oct 29 '20 14:10 kunalvashistordway

Could you please provide example of code to reproduce the issue?

andrykonchin avatar Oct 31 '20 12:10 andrykonchin

The only thing I remember is that associations don't work now when primary key is compound - when there is a range/sort key. So WorkflowLog cannot belong to a model with range/sort key.

andrykonchin avatar Oct 31 '20 12:10 andrykonchin