Dynamoid icon indicating copy to clipboard operation
Dynamoid copied to clipboard

Field name for id hard-coded in ManyAssociation:<<

Open lisad opened this issue 11 years ago • 3 comments

In the ManyAssocation module, the method to add an item to an association assumes that the item's id field is called ':id'. Shouldn't it use the key field defined when the table is set up?

My code:

class Plan
  include Dynamoid::Document
  table :name => :events_plans, :key => :plan_id, :read_capacity => 400, :write_capacity => 400

  belongs_to :event
end

In the console:

$  an_event.plans << new_plan

The dynamoid ManyAssociation code with the hardcoded :id in the 1st line of the method:

      def <<(object)
        source.update_attribute(source_attribute, source_ids.merge(Array(object).collect(&:id)))
        Array(object).each {|o| self.send(:associate_target, o)} if target_association
        object
      end

lisad avatar Oct 07 '13 17:10 lisad

Note that I also tried to use the Rails3 ActiveRecord method "set_primary_key", but that seems not to be implemented in Dynamoid::Document.

(http://apidock.com/rails/ActiveRecord/AttributeMethods/PrimaryKey/ClassMethods/set_primary_key)

lisad avatar Oct 07 '13 17:10 lisad

Hi Lisa,

That does, indeed sound like a bug. Any chance you can put together a pull request with a fix + the requisite spec?

loganb avatar Oct 07 '13 18:10 loganb

I'm planning to contribute at some point but I'd like to get more of a feel for DynamoDB and Dynamoid first. I just started this week with both. We're also on a release deadline at work :)

lisad avatar Oct 07 '13 18:10 lisad